This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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

inheritance problem

James Brooks
Gunslinger
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);
System.out.println(mySquare.computeSurfaceArea());
Cube myCube = new Cube(1.0, 2.0, 3.0);
System.out.println(myCube.computeSurfaceArea());
}
}


Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritance problem