Some basic concepts of abstract classes
Directory
Use [TOC] to generate a table of contents:
Some basic concepts of abstract class catalog abstract conceptual code block
The concept of abstraction
Abstract method: In Java, a method without a method body is defined as an abstract method.
Abstract class: If there is an abstract method in a class, the class is defined as an abstract class.
1> Abstract class overview:
animals should not be defined as specific things, and animals eat, sleep, etc. should not be specific.
we call a function that is not specific as abstract, and if there is an abstract function in a class, the class must be an abstract class.
2> The characteristics of abstract classes:
A: Abstract classes and abstract methods must be decorated with the abstract keyword
B: there is not necessarily an abstract method in an abstract class, but a class with an abstract method must be defined as an abstract class
C: An abstract class cannot be instantiated
because it is not concrete.
Abstract classes have construction methods, but cannot be instantiated? What
is the role of the construction method? Initialization of a subclass that accesses the parent class
D: Abstract Subclass
A: If you do not want to override an abstract method, the subclass is an abstract class.
B: Rewrite all the abstract methods, this time the subclass is a concrete class. The instantiation of an
abstract class is actually implemented by a specific subclass. is the polymorphic way.
Animal a = new Cat ();
3> the members of an abstract class:
member variables: can be either a variable or a constant.
Construction Method: there is.
used to initialize the subclass to access the data of the parent class.
member methods: can be abstract or non-abstract.
4> The member method attributes of an abstract class:
A: Abstract methods < forcing the subclass to do things >.
B: Non-abstract methods < subclass inherited things, improve code reuse >
code block
code block syntax follows standard markdown code, such as:
abstract class animal{int age=20;
final int age2=40;
Public Animal () {} public Animal (String Name,int age) {} public abstract void Show ();
public void Method () {System.out.println (' Animal method ');
Class Dog extends animal{public void Show () {System.out.println (""); } public class AbstactDemo2 {public static void main (string[] args) {//TODO automatically generated method stub Animal A=ne
W Dog ();
a.age=10;
a.age3=30;
System.out.println (A.age);
System.out.println (A.age2); }
}