Java Abstract classes and interfaces
1. abstract class/** 1. abstract METHODS must exist in abstract classes. abstract methods and abstract classes must be modified! 2. abstract classes cannot be instantiated. 3. If multiple abstract methods exist in an abstract class and its subclass only inherits one abstract method, the subclass is an abstract class and therefore cannot be reinforced. 4. An abstract class can only create a subclass object if the quilt class overwrites all its abstract methods! 5. the abstract class may contain non-Abstract METHODS * // This subclass does not overwrite the abstract method of the parent class func1. Therefore, the subclass is an abstract class and 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 (); // The subclass is an abstract class and cannot be instantiated. func () ;}/// this parent class does not contain abstract methods, the class name is not abstract modified, 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 (); // The subclass is an abstract class and cannot be instantiated. func () ;}} 2. interface/** 1. all methods in the interface are abstract methods, so they can be considered as abstract classes. 2. the interface member has a fixed modifier constant: public static final method: public abstract. All methods in the interface have the public permission. */Interface Inter {public static final int NUM = 3; public abstract void show ();} class SubInter implements Inter {public void show () {System. out. println ("implementation interface! ");} Class InterfaceDemo {public static void main (String args []) {SubInter sb = new SubInter (); sb. show ();}