Abstract classes are used less in Java, and Java translates abstract classes into interfaces. Abstract class from the point of view of the code is to ask others to implement the method also has its own method of implementation. Abstract classes are used in C + +
Very good, abstract class in C + + is to do the canonical type. In the illustration of 1.4 animals, animal classes only make simple method declarations, while non-rewriting or less-rewritten methods in subclasses do not
Come to the wrong, since will not report the error so the customer will not obey the rules may be less write one or several methods, this is not strict, this problem is large, can not let subclasses selectively rewrite. So in order to
To make programming for the parent class more perfect, then we have to write the animal class as an abstract class and write it as an abstract class that must be forced to rewrite. So the abstract class customizes this rule for rigorous execution.
8.8 is shown below:
Figure 8.8
First, turn the Test2 class into an abstract class, and then turn the method into an abstract method with a semicolon, because he does not need to be implemented so that no curly braces are required. The benefit of an abstract method is that the subclass is forced to require
Must be overridden. If you do not re-will be an error. From the point of view of the code is to write the abstract must rewrite him or error. This will not only prevent mistakes but also unify the rules so that the code can continue to send
The show goes on.
Abstract class is divided into ordinary abstract class and pure abstract class, pure abstract class is inside all is abstract method. Ordinary abstract class is the inside there are abstract methods and methods of implementation. 8.81 is shown below:
Figure 8.81
In real life, a person is a lot of identity, if you work is the identity of employees, if you go to the mall is the identity of customers. So in this respect, we have different bodies in different environments.
Report
Abstract class is divided into pure abstract class and ordinary abstract class, pure pumping like class is all methods are abstract methods, ordinary pumping like there is not an abstract method. 8.82 is shown below:
Figure 8.82
Abstract class He can not be a static method, he is to give the example to set the method. Abstract classes also cannot be new objects because he is an abstract concept that requires subclasses to implement.
Technology sharing: www.kaige123.com
Java abstract class