• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance problem

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic