ManMade subclass with 2 constructors and 3 instance variables

  • Context: Java 
  • Thread starter Thread starter courtrigrad
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
courtrigrad
Messages
1,236
Reaction score
2
Hello all

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

Code:
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
 
Physics news on Phys.org
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

Code:
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..).
 
Last edited:
courtrigrad said:
Hello all

Code:
     public ManMade()
    {
        super(0, 0); // call the superclass contructor
        name = ;
    }
Where is the
Code:
Thing
constructor with two arguments?