This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Murach's Java Programming and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

inheritance problem  RSS feed

James Brooks
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);
Cube myCube = new Cube(1.0, 2.0, 3.0);
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!