A novice Java abstract

In Java, a method is no method body should define abstract methods, two into the class if there is an abstract method, the class must be defined as an abstract class

We are not a specific feature called an abstract function, and if there is a class in the abstract functional class must be abstract class.

Characteristics abstract class:
abstract classes and abstract methods must be modified with the abstract keyword
format:
abstract class name of the class} {
public abstract void EAT ()

An abstract class may not have abstract methods, abstract methods of the class must be abstract class.
An abstract class can not be instantiated.
Because he was not specific

So, how to instantiate an abstract class it?
The multi-state mode, by the particular instance of a subclass of fact, this is a multi-state, multi-state abstract class

Abstract subclass
1 or is an abstract class
for all abstract methods are either rewritable 2. abstract class


Members of the abstract class characteristics:
member variables: either the variable, or may be a constant
constructor: Initializes access to the parent class for the subclass data
members methods: either abstract, may be non-abstract

Member methods characteristic of abstract classes:
things to do mandatory sub-categories: A: an abstract method
B: a non-abstract methods: subclass inherits things, improve code reusability

If a class is not abstract methods, Can be defined as an abstract class? If so, what is the point?
A: Yes
B: not to create objects

abstract and keywords that can not coexist
private conflict // private, so can not be rewritten, and rewritten abstract requirements, so conflicts
final conflict // final, it can not be rewritten, and rewritten abstract requirements, so the conflict
static meaningless // static methods in the abstract can be called directly, because the abstract method is no method body, so the reference to a static abstract method does not make sense

Published 88 original articles · won praise 47 · views 10000 +

Guess you like

Origin blog.csdn.net/dai_ma_dong/article/details/95895302