Create an abstract class Shape with method display (). Create two class Rectangle and Circle which extend this Shape class and use method display () of it.
import java.io.DataInputStream;
abstract class Shape
{
abstract void display(int a,int b);
}
class Rectangle extends Shape
{
int rec;
void display(int l,int b)
{
rec=l*b;
System.out.println("Ractangle are :===>"+rec);
}
}
class Circle extends Rectangle
{
float ans;
void display(float r)
{
ans=3*r*r;
System.out.println("Circle are:===>"+ans);
}
}
class AbstractMethod
{
public static void main(String args[])
{
int a,b,c;
try
{
DataInputStream obj=new DataInputStream(System.in);
Circle cn=new Circle();
System.out.print("Radius--->");
a=Integer.parseInt(obj.readLine());
System.out.print("Lenth---->");
b=Integer.parseInt(obj.readLine());
System.out.print("Breadth-->");
c=Integer.parseInt(obj.readLine());
cn.display(a);
Rectangle r=new Rectangle();
r.display(b,c);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
0 comments:
Post a Comment