Constructor Inheritance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javatech007
    New Member
    • Nov 2007
    • 51

    Constructor Inheritance

    I am having trouble inheriting constructors in my project. I am trying to assign a ValueRadius in the child Orange class that will fit in with my ValueA and Value B in the parent class Shapes_5. I also want to add additional getter and setter method for ValueRadius.

    Below is my code so far :

    code: (JAVA)
    public class Shapes_5
    {
    public static void main(String[] args)
    {

    Shapes_Values c = new Shapes_Values() ;

    c.setValueA(5);
    c.setValueB(14) ;

    c.goToPrinter() ;

    }
    }



    class Shapes_Values
    {

    int ValueA;
    int ValueB;


    void setValueA(int iValueA) //setter method
    {

    ValueA = iValueA;

    }


    void setValueB(int iValueB) //setter method
    {

    ValueB = iValueB;

    }

    int getValueA() //getter method
    {

    return ValueA;

    }

    int getValueB() //getter method
    {

    return ValueB;

    }

    void goToPrinter() //Outputs the coordinates of the shape
    {

    System.out.prin tln("[" + ValueA + "," + ValueB + "]");

    }

    }


    class Orange extends Shapes_5
    {
    protected int ValueRadius=2;

    public Orange(int iValueA, int iValueB)
    {
    super(iValueA,i ValueB);
    }
    class Shapes_Values
    {
    int ValueRadius;

    void setValueRadius( int iValueRadius) //setter method
    {

    ValueRadius = iValueRadius;

    }

    int getValueRadius( ) //getter method
    {

    return ValueRadius;

    }

    }
    }
  • javatech007
    New Member
    • Nov 2007
    • 51

    #2
    An error appears when I compile it saying 'cannot find symbol' for the line

    super(iValueA,i ValueB);

    in the orange class!!

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by javatech007
      An error appears when I compile it saying 'cannot find symbol' for the line

      super(iValueA,i ValueB);

      in the orange class!!
      That's because the super class of your Orange class (which is the shape_5 class)
      doesn't have a constructor that takes two arguments. Constructors aren't inherited
      nor are they 'automagically' written for you by the compiler.

      kind regards,

      Jos

      Comment

      • javatech007
        New Member
        • Nov 2007
        • 51

        #4
        Thanks,

        how would I get the constructor to take two arguments then??

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by javatech007
          Thanks,

          how would I get the constructor to take two arguments then??
          Erm, implement one in the super class or don't try to call one in the super class?

          kind regards,

          Jos

          Comment

          Working...