Abstract class
1. Syntax definition: Use abstract keyword decoration before abstraction class
2. Application Scenario
A, the parent class only knows what kind of method the subclass contains, and does not know how the method is implemented (the constraint subclass must have a method)
B, from a class with the same characteristics, abstract a class, with this abstract class as a subclass template, so as to avoid the arbitrary design of sub-class
3, role: Limit the subclass must have those methods, do not pay attention to the specific details
4. Rules of Use:
A, abstract defines a class that modifies abstractions
B, abstract defines an abstraction method, declares only, does not need to implement
C, classes that contain abstract methods are abstract classes
D, abstract classes can contain ordinary methods, or there can be no abstract method.
E, abstract classes cannot be created directly, you can define reference variables, point to child class objects
Example: Define an abstract class phone (parent class) whose subclasses have cellphone and smartphone. Defining abstract class Methods: Call and Message
Test class:
Question 1: In the creation of inherited phone abstract parent class when the line error, press F2 to find the problem and according to the prompt to modify (delete @override and then reopen it)
--reason: Compiler version issue
Question 2: When creating the smartphone subclass, accidentally ticked the abstract, and made an abstraction class, so in the main function (test Class) in the smartphone instantiation of the failure
--reason: cannot instantiate an abstract class
When defining the Smartphone class, add the abstract modifier and delete it.
Abstract class for Java