• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inheritance problem

 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a strange one for you... I'm into inheritance now in this book, and my constructors clearly send 2 and 3 double arguments to the Square and Rectangle classes, respectively, but their values are 0, according to the system.out statements I have in the program. Anyone have any idea why?
Parent class:

package ch11;
import java.lang.Math;

public class Cube extends Square
{
double length;
public Cube(double h, double w, double l)
{
super(h, w);
length = l;
}
public double getLength()
{
return length;
}
public double computeSurfaceArea()
{
return ((super.computeSurfaceArea()*2) + java.lang.Math.pow((length*height), 2) +
java.lang.Math.pow((width*length), 2));
}
public static void main(String[] args)
{
Square mySquare = new Square(1.0, 2.0);
System.out.println(mySquare.computeSurfaceArea());
Cube myCube = new Cube(1.0, 2.0, 3.0);
System.out.println(myCube.computeSurfaceArea());
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic