Abstract Class is used to make some methods compulsory for subclasses to redefine them according to the subclass.
Thus it provide basic about the functions which an object has to perform .
Syntax: abstract type name(parameter list);
If a method is abstract then the class must be declared abstract. All the subclasses have to define that method.
Following will illustrate the concept:
Code::
abstract class Base
{
abstract void show();
}
class Derived extends Base
{
void show()
{
System.out.println("Derived Show");
}
}
public class AbstractUse
{
public static void main(String [] nt)
{
// Base b=new Base(); Compile time error
Derived d=new Derived();
d.show();
Base n; //abstract class reference can be created
n=d;
n.show();
}
}
Output::
Thus it provide basic about the functions which an object has to perform .
Syntax: abstract type name(parameter list);
If a method is abstract then the class must be declared abstract. All the subclasses have to define that method.
Following will illustrate the concept:
Code::
abstract class Base
{
abstract void show();
}
class Derived extends Base
{
void show()
{
System.out.println("Derived Show");
}
}
public class AbstractUse
{
public static void main(String [] nt)
{
// Base b=new Base(); Compile time error
Derived d=new Derived();
d.show();
Base n; //abstract class reference can be created
n=d;
n.show();
}
}
Output::