package javaapplication24;
abstract class shape
{
public abstract void printarea();
}
class triangle extends shape
{
float b,h;
public void printarea()
{
System.out.println("area of triangle is "+0.5*b*h);
}
}
class square extends shape
{
float s;
public void printarea()
{
System.out.println("area of triangle is "+s*s);
}
}
public class JavaApplication24 {
public static void main(String[] args)
{
triangle t=new triangle();
t.b=5;
t.h=10;
t.printarea();
square s=new square();
s.s=2.5f;
s.printarea();
}
}
No comments:
Post a Comment