1. Abstract class/**1. Abstract methods must exist in the abstract class, abstract methods and abstract classes need to be abstract!2. abstract class cannot instantiate .3. if there are multiple abstract methods in the abstract class, and its subclasses inherit only an abstract method, The subclass is an abstract class, so it cannot be powerful. 4. abstract class can only be used to cover all of its abstract methods to create sub-class objects! 5. Abstract classes can have non-abstract methods *///The subclass does not overwrite the parent class Func1 abstract method, so the subclass is abstract class, cannot be instantiated. Compilation failed Abstract class person{ abstract void func (); abstract void func1 (); void func2 () {    SYSTEM.OUT.PRINTLN ("Non-abstract Method 2! "); };} Class student extends person{ public void func () {       SYSTEM.OUT.PRINTLN ("Non-abstract Method! "); }}class abstractdemo{ public static void main (String[]args) { student st =new student ();//subclass is abstract class, cannot instantiate &nbsP; st.func (); } }//the parent class does not have an abstract method, the class name has not been modified by the abstract, and the compilation fails Class person{ abstract void func ( ); //abstract void func1 (); void func2 () {        SYSTEM.OUT.PRINTLN ("Non-abstract Method 2! "); };} Class student extends person{ public void func () {       SYSTEM.OUT.PRINTLN ("Non-abstract Method! "); }}class abstractdemo{ public static void main (String[]args) { student st =new student (); st.func (); } }//compiled successfully abstract class person{ abstract void func (); //abstract void func1 (); void func2 () {        SYSTEM.OUT.PRINTLN ("Non-abstract Method 2! "); };} Class student extends person{ public void func () {       SYSTEM.OUT.PRINTLN ("Non-abstract Method! "); }}class abstractdemo{ public static void main (String[]args) { student st =new student ();//subclass is abstract class, cannot instantiate st.func (); } }2. All the methods in the interface/**1. interface are abstract methods, so they can be regarded as the abstract class of the special vulgar 2. The members of the interface have fixed modifiers constant: public static final method: public abstract, all methods in the interface are public permissions. */interface Inter{ public static final int num = 3; public abstract void Show ();} Class subinter implements inter{ public void show () {        SYSTEM.OUT.PRINTLN ("Implement Interface! "); }class interfacedemo{ public static void main (string args[]) { subinter sb = New subinter (); sb.show (); } }
This article is from the "Sima" blog, make sure to keep this source http://9274590.blog.51cto.com/9264590/1695656
Abstract classes and Interfaces in Java