In
Java, it is possible to define a method that must always be redefined in a
subclass, thus making overriding compulsory. This is done using the keyword abstract in the method definition.
Ex:
abstract class A {
…….
abstractvoid show();
…….
}
When
a class contains one or more abstract methods, it should also be declared abstarct.
While
using abstract classes, the following conditions must be defined:
o We
can’t use abstract classes to instantiate objects directly:
Ex:A
a=new A(); is illegal because a is an abstract class.
o Abstarct
method of an abstract class must be defined in its subclass.
o
We can’t declare abstract
constructors or abstract static methods.
No comments:
Write comments