Hi I have three classes Cal, Cal2 and Inheritance5
Cal is parent, Cal2 extends Cal and Inheritance basically tries to find the total.
Problem: When I try to compile and execute my Inheritance5.java program it prints 0 instead of 12 why is that and is there a way for me to execute it without using super statement or adding another constructor in child class that accepts 2 ints? Please help.
public class Cal
{
private int base, height, total;
Cal(){}
Cal(int b, int h)
{
base = b;
height = h;
}
public void setHeight(int num)
{
height = num;
}
public void setBase(int num)
{
base = num;
}
public void getTotal()
{
System.out.println("Area of the rectangle is " + (base*height));
}
}
=====================================================================
public class Cal2 extends Cal{
}
======================================================================
public class Inheritance5{
public static void main(String[] args){
Cal2 areaRectangle = new Cal2(4,3);
areaRectangle.getTotal();
}
}