Abstract Class
Abstract Class
OUTPUT : Woof
abstract class MyClass
{
p u b l i c void d i s p ( )
{
System.out.println("Concrete method o f parent c l a s s " ) ;
}
abstract p u b l i c void d i s p 2 ( ) ;
}
class Demo extends MyClass
{
p u b l i c void d i s p 2 ( )
{
S y s t e m . o u t . p r i n t l n ( " ab s t r ac t method has
implemented");
}
p u b l i c s t a t i c void main(String a r g s [ ] )
{
Demo obj = new Demo();
obj.disp2();
}
}
OUTPUT : overriding abstract
method
USE OF ABSTRACT
CLASS
• To share code among several closely related classes.
• If classes that extend your abstract class have many common
methods or fields or require access modifiers other than
public (such as protectedand private).
• You want to declare non-static or non-final fields. This
enables you to define methods that can access and modify
the state of the object to which they belong.