*--summarize Java abstract classes and interfaces
* 1. Abstract class:
* 1 Abstract class can modify the method, modify the class, but cannot modify the property, cannot be instantiated
* 2 abstract class can be inherited, can only be single inheritance, inherit abstract class must implement abstract method
* 3 abstract class cannot be modified with static, Fina,private
* 4 abstract class is polymorphic
*
* 2. Interface:
* 1 "interface is a special kind of abstract class, cannot be instantiated
* 2 The properties of the interface declaration The default keyword is public abstract static
* 3 The method of the interface declaration The default keyword is public abstract
* 4 The interface can be inherited, the interface can be inherited multiple, can also inherit multiple
* 5 "interface is polymorphic
*
PackageCome.java.zhangfan.test3; Public classTest { Public Static voidMain (string[] args) {Students s=NewStudents (); T1 (s);//Output---woshi StudentT T=NewT (); T (t); } //the polymorphism of abstract classes Public Static voidT1 (person p) {p.t (); } //the polymorphism of the interface Public Static voidt (Runner p) {p.run ();//Output--- Woshi Run }}//application of abstract class//declaring abstract ClassesAbstract classperson{//the modifier for field I is not legal; only public, protected, private, static, end state, transient, or variable are allowed.//property cannot be overwritten//abstract int i; //abstract methods in type person T can only set one of the visual modifiers "public" or "protected"//If static then means that you can call the method without creating an object directly, conflict with Abstact//abstract static public void T (); //abstract methods in type person T can only set one of the visual modifiers "public" or "protected"//itself on the conflict, does not explain//abstract Final public void T (); //abstract methods in type person T can only set one of the visual modifiers "public" or "protected"//private methods cannot be overwritten//abstract private void T (); Abstract Public voidT ();//True}//declare a student class to inherit the abstract class and override the T methodclassStudentsextendsperson{ Public voidT () {System.out.println ("Woshi Student"); }}//application of the interfaceInterfacerunner{ Public Abstract voidrun ();}Interfaceswimmer{voidswim ();}InterfaceFlier {voidfly ();}//interfaces can inherit multipleInterfaceTextendsrunner,swimmer,flier{}//all inherited methods must be declaredclassT1Implementst{@Override Public voidrun () {//TODO Auto-generated method stubs} @Override Public voidswim () {//TODO Auto-generated method stubs} @Override Public voidFly () {//TODO Auto-generated method stubs } }//interfaces can be multi-referenced//all inherited methods must be declaredclassTImplementsflier,runner,swimmer{@Override Public voidFly () {//TODO Auto-generated method stubsSystem.out.println ("Woshi Fly"); } @Override Public voidswim () {//TODO Auto-generated method stubsSystem.out.println ("Woshi Swim"); } @Override Public voidrun () {//TODO Auto-generated method stubsSystem.out.println ("Woshi Run"); } }
Java learning Experience-summarizing Java abstract classes and interfaces