Java Abstract class "instantiation", java Abstract
Without doubt, abstract classes cannot be instantiated. abstract classes do not describe a specific thing as a specific class. They extract the abstract of common features of similar specific things, and it has no meaning to implement them.
If the abstract class is not inherited but is "instantiated", the statement is as follows:
1 package subClass; 2 abstract class ParentClass {3 public abstract void abstractFun (); 4} 5 6 class SubClass {7 // here "instantiate" ParentClass is instantiated ParentClass (){}, and implements the abstract method of ParentClass. Therefore, the abstract class cannot be instantiated. 8 ParentClass parentClass = new ParentClass () {9 @ Override10 public void implements actfun () {11 System. out. println ("abstractFun ()"); 12} 13}; 14 15} 16 17 public class TestExtends {18 public static void main (String args []) {19 SubClass sub = new SubClass (); 20 sub. parentClass. abstractFun (); 21} 22}
Instantiate "ParentClass is new ParentClass () {}, and implements the abstract method of ParentClass, instead of newParentClass ().
The above structure is similar to Android event listening:
FindViewById (R. id. stop_Button). setOnClickListener (new View. OnClickListener (){
@ Override do not think it is an internal class when @ Override is omitted here.
Public void onClick (View v ){
StopService (it );
}
});
Abstract class features:
The abstract class must be inherited from non-abstract classes;