Abstract class Features: 1. When a method is declared without a specific implementation, it needs to be decorated with the abstract modifier. Abstract methods must be defined in abstract classes, so abstract classes also need to be decorated with an abstract 2. Abstract classes can not be instantiated, why? Because calling an abstract method doesn't make sense 3. Subclasses of an abstract class must overwrite all of the parent class's abstract methods before the subclass can be instantiated, or the subclass is abstract;
class A
extends Chouxiang { @Override
void bark () {///Only the bark () method is overridden to instantiate Class A //
TODO auto-generated Method StubSystem.
out. println ("What do you mean?"); }}
Public
Abstract
class Chouxiang {
Abstract
void bark ();//must have subclasses rewritten to make sense
Private
int Bark (
int a,
int b There can be non-abstract methods in the {///abstract class, that is, you do not need the subclass to override the method
return a + b; }
Public
Static
void Main (string[] args) {A a =
New A (); a. Bark ();//The Overridden bark () method is called }}
- Are there constructors in abstract classes?
there are, for the initialization of a subclass
- Can there be no abstract method in an abstract class?
Yes, but it's rare to keep subclasses from creating objects
- Abstract classes are not available and which keywords to use
1.private: Private decorated methods in the parent class are not visible to subclasses, that is, subclasses cannot overwrite methods 2.static: When using the static modifier, you can call the method directly using the class name, so that the subclass does not have to be implemented; Even calling directly is just a method declaration, and it doesn't make sense. The meaning of 3.final:abstract is to allow subclasses to overwrite the modified method, but final is not allowed to overwrite the method, the contradiction between the two
- The Star class must be a parent class.
Yes, because it makes sense to need its subclasses to cover its methods.
Introduction to the abstract class of Java basics