First, abstract class
1. What is abstract class
For a method of a class, you can describe one of these attributes. such as the animal's running, but different objects may not be the same way.
This requires an abstraction of the method. This allows for inheritance based on the characteristics of different classes, and then overrides the abstract method.
Abstract class * *
{
abstract void * * ();
}
2, the characteristics of abstract class
(1) Abstract classes can not be instantiated
(2) Abstract methods of abstract classes are simply declared and not implemented. Method is described by the keyword abstract. Abstract methods corresponding to the abstract class, also to be described by the abstract keyword.
(3) After being inherited in an abstract class, all of the abstract methods must be implemented. Otherwise, it is an abstract class and cannot be instantiated.
3. Some problems of abstract class
(1) Abstract class has no constructors
An abstract class has a constructor function. Abstract classes will have subclasses, and constructors in abstract classes can initialize subclasses.
(2) Abstract methods can not be defined in abstract classes?
OK!
Rarely, the purpose is not to let it create objects.
(3) What keywords cannot be used to coexist with abstract keywords?
Private cannot be, because abstract methods are overwritten, and private methods cannot be overwritten.
Static can not
Final cannot be
(4) Similarities and differences between abstract classes and general classes?
Same: Both describe the class's
Different: abstract class only declaration, no specific description.
Abstract methods cannot be defined in a generic class, and abstract methods can be defined in an abstract class.
(5) Abstract class must be a parent class?
Yes! Subclasses need to overwrite their methods in order to instantiate!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java programming Idea--abstract class