I. What is abstract class
Abstract classes are often used to characterize the abstract concepts of analysis and design of problem areas, and are abstractions of a series of concrete concepts that look different, but are essentially the same. An abstract class is incomplete and can only be used as a base class.
Two. How are abstract classes implemented?
Abstract classes contain abstract methods, abstract methods use the keyword abstract modification, and the abstract method has no method body.
Abstract method:
Abstract void F1 (); // method body cannot appear
Note: Abstract classes can contain non-abstract methods.
Because an abstract class cannot be instantiated, you can use inheritance to abstract the parent class in such a way that the subclass implements all of the parent class's abstract methods , and then instantiates the child class.
The code is as follows:
Public classAbstractclasstext { Public Static voidMain (string[] args) {A A1=NewB ();//abstract types can use polymorphic//a a2= new A ();//Abstract classes cannot be instantiated. B B1 =NewB ();//subclasses of all methods that implement an abstract class can be instantiated }}/** Abstract Class A, which contains abstract methods, cannot be instantiated*/Abstract classA {Abstract voidF1 ();//method body cannot appear Abstract voidF2 (); voidF3 () {; }}classBextendsA {@OverridevoidF1 () {System.out.println ("Class B implements the F1 method of Class A"); } @OverridevoidF2 () {System.out.println ("Class B implements the F2 method of Class A"); }}
Three. Abstract class and Polymorphic
Although abstractions cannot be instantiated, they can be polymorphic.
Abstract classes in Java