A class with ‘abstract’ modifier is called as abstract class
in Java. Abstract class in Java may or may not contain abstract; it is not
mandatory for abstract class to have abstract methods.
In Java you cannot create instance of ‘abstract’ class and so
if you want to use ‘abstract’ class then you must extend it as subclass/child
class for another class which is not abstract.
If you know only know the partial implementation of class
then you can declare it as ‘abstract’. Abstract class may or may not contain
abstract method and non abstract methods i.e. you may or may not have methods
with implementation (non-abstract methods) or methods without implementation
(abstract methods) in an abstract class.
Main use of abstract class is to force the provider of
subclass to implement unimplemented methods of abstract parent class.
Writing
the abstract class:
i.
A class containing at least one abstract must be
declared abstract.
ii.
Instance variables, instance methods, constructors and
instance blocks are allowed inside the abstract block.
iii.
Static variables, static methods and static blocks are
allowed inside the abstract block.
iv.
You cannot use ‘static’, ’final’ modifiers with
abstract class declaration.
v.
‘private’, ’protected’ modifiers cannot be used with
top level abstract class declaration.
0 comments:
Post a Comment