class Triangle{
double base, height;
Triangle(){
base = 0;
height = 0;
}
Triangle(double base, double height){
this.height = height;
this.base = base;
}
Triangle(double len){
height = len;
base = len;
}
void area(){
System.out.println("The area of a Triangle is: " + 0.5*base*height);
}
}
class Demo extends Triangle{
double length;
Demo(double b, double h, double l){
base = b;
height = h;
length = l;
}
void area(){
System.out.println(base*height*length);
}
}
public class Main{
public static void main(String args[]){
Triangle tri = new Triangle(5.0,3.0);
Demo dm = new Demo(3.0,7.0,5.0);
tri.area();
dm.area();
}
}
Using super class Constructor
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment