File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes inheritance problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance problem" Watch "inheritance problem" New topic

inheritance problem

James Brooks
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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);

Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
I agree. Here's the link:
subject: inheritance problem