[Abstract]

Abstract class overview:
In java, a body methods should not be defined as an abstract method, if the abstract class methods, class must be defined as an abstract class.
 
Abstract class features:
A: abstract classes and abstract methods must be modified with the abstract keyword. format:
abstract class class name ()
public abstract void eat();
B: abstract class is not necessarily abstract methods, but the method must be defined abstract class as an abstract class.
C: An abstract class is not instantiated
Because it is not specific.
Abstract classes have constructors, but can not be instantiated, the constructor of what role is it? Subclasses for initializing the access to the parent class data.
D: abstract subclass:
a. If you do not want to override the abstract method, which is a subclass of abstract class.
B. rewrite all the abstract methods, this time is a concrete subclass of class.
E: How to instantiate an abstract class?
Instantiation is actually achieved by specific subclasses of abstract classes. Examples of the way of polymorphic.
 
Features abstract class members:
Member variables: either a variable, it can be constant.
Constructor: Yes. Subclasses for initializing the access to the parent class data.
Member methods: either abstract or a non-abstract.
Abstract class member method characteristics:
A: abstract method: mandatory sub-class thing to do.
B: non-abstract methods: subclass inherits things, improve the reusability of code.
 
 
Several questions abstract class:
1. If a class is not abstract methods, Can be defined as an abstract class? If so, what is the point?
A: Yes. Meaning: not to create objects. To access it must be accessed through its subclasses.
2.abstract and which keywords can not coexist?
private conflict
final clash
static meaningless

Guess you like

Origin www.cnblogs.com/zuixinxian/p/11276390.html