Features of abstract classes:
A: Abstract classes and abstract methods must be decorated with the abstract keyword.
B: Abstract classes do not necessarily have abstract methods, but classes of abstract methods must be defined as abstract classes
C: An abstract class cannot be instantiated because it is not specific.
An abstract class has a constructor method, but cannot be instantiated? What is the function of the construction method?
Initializes the child class to access the parent class data.
D: An abstract subclass.
If you do not want to override the method of an abstract class, the subclass is an abstract class. Rewrite all the abstract methods, this time the subclass is a concrete class
Abstract class Demo:
//Abstract class Animal//declarative format for abstract classesAbstract classAnimal {//Abstract Methods//Public abstract void Eat () {}//empty method body, this will be an error. Abstract methods cannot have principals Public Abstract voideat (); PublicAnimal () {}}//subclasses are abstract classesAbstract classDogextendsAnimal {}//subclasses are concrete classes, overriding abstract methodsclassCatextendsAnimal { Public voideat () {System.out.println ("Cat Eats fish"); }}classAbstractdemo { Public Static voidMain (string[] args) {//Creating Objects//animal is abstract; unable to instantiate//Animal a = new Animal (); //by polymorphic meansAnimal A =NewCat (); A.eat (); }}
Java Learning (vii) abstract classes in Java