Java Programming- Example of Abstract Class and Abstarct Method
//Abstract Class is a class which contains atleast one abstract method. Abstract class cannnot be instantiated i.e. object cannot be created for that class. The methods are implemented in the subclass or base class.
import java.io.*;
abstract class Shape //Abstract Class
{
abstract void draw(); //Abstract Method
}
class Rectangle extends Shape{
void draw()
{
System.out.println("Draw Rectangle Here");
}
}
class Traingle extends Shape
{
void draw()
{
System.out.println("Draw Traingle Here");
}
}
class AbstractClass Example
{
public static void main(String args[])
{
//Shape s=new Shape();//This ia Illegal Now
Shape ob1=new Rectangle();
ob1.draw();
Shape ob2=new Traingle();
ob2.draw();
}
}
OUTPUT
import java.io.*;
abstract class Shape //Abstract Class
{
abstract void draw(); //Abstract Method
}
class Rectangle extends Shape{
void draw()
{
System.out.println("Draw Rectangle Here");
}
}
class Traingle extends Shape
{
void draw()
{
System.out.println("Draw Traingle Here");
}
}
class AbstractClass Example
{
public static void main(String args[])
{
//Shape s=new Shape();//This ia Illegal Now
Shape ob1=new Rectangle();
ob1.draw();
Shape ob2=new Traingle();
ob2.draw();
}
}
OUTPUT
Comments
Post a Comment