PDA

View Full Version : Superclasses and Subclasses


courtrigrad
Dec8-04, 12:55 PM
Hello all

I need help in writing a subclass (ManMade) that has 2 constructors and 3 isntance variables. Here is my code so far:


public class Thing
{



private double length; // instance variables (fields)
private double height;
private double width;
private boolean isPurpleFox;
private double age;
private static boolean exists;

//*******************************//

public Thing()
{
length = 7;
height = 8;
isPurpleFox = false;
age = 0;
exists = true;
width = 10;
}
//======================================
public double getlength()
{
return length;
}

public void setAge(double a)
{
age = a;
}

public double getage()
{
return age;
}
public boolean getexists()
{
return exists;
}

public void setexists(boolean b)
{
exists = b;


}
public void Triple(int a)
{
a = a*3;
System.out.println(a);
}


public Thing (double l, double w, double h )
{
length = l;
width = w;
height = h;

}
}




// Subclass of Superclass
// Thing

public class ManMade extends Thing { // inherits from Thing
private string name;
private double volume;
private double surfarea;

// no argument constructor
public ManMade()
{
super(0, 0); // call the superclass contructor
name = ;
}

// Constructor
public ManMade( double l, double, w, double h, char s )
{
super( l, w, h); // call the superclass constructor
setName( "Bob" )
setVolume( v );
setSurarea( S );


I am not sure whether i am doing this right.

any help is appreciated

Nylex
Dec8-04, 01:04 PM
When you post code, can you please say what you want to do. What is it that you aren't sure of?? You make a subclass by using the extends keyword, like you've done, so what's the problem? All I can see a problem is with the line

name = ;

You need to write name = " "; cos otherwise the code won't compile (obviously you won't be able to compile that code on its own, as there's no main(), but you know..).

ramollari
Dec10-04, 03:13 AM
Hello all


public ManMade()
{
super(0, 0); // call the superclass contructor
name = ;
}



Where is the Thing constructor with two arguments?