Abstract Methods and Abstract Classes: Abstract Methods
Abstract Methods and Abstract Classes: Abstract Methods
Abstract Methods:
It indirectly implies having child class for defining that method i.e. the
class also should be declared as abstract class. Hence, abstract methods
and abstract classes go hand in hand. To put it in simple words, when a
class has an abstract method, the class also should be declared as an
abstract class. Constructors and static methods can never be abstract.
Abstract classes:
Abstract classes are the classes which can be sub classed but not
instantiated.
abstract class Shape
{
abstract void draw( );
void draw()
…….
void draw()
…….
class Test
Shape s1;
s1=new Rectangle();
s1.draw();
s1=new Triangle();
s1.draw();