Constructor Help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SpecialKay
    New Member
    • Mar 2008
    • 109

    #1

    Constructor Help!

    I have a shape SquareEx that extends Shape Square.

    [code=java]
    public class SquareEx extends Square {
    private Color Shadow = Color.RED;

    SquareEx(int x, int y){
    super.setX(x);
    super.setY(y);
    }
    [/code]

    when i try and run, i get the error:

    Error(7,26): constructor Square() not found in class Square

    know why?
  • SpecialKay
    New Member
    • Mar 2008
    • 109

    #2
    [code=java]

    public class Square extends Shape {

    Square(int x, int y) {
    setX(x);
    setY(y);
    }

    [/code]

    here is my Square code,

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      When you inherit from a class, the derived class's constructor must call the base class's constructor. If you don't explicitly call it (super(params)) , then the compiler includes a call to a no-parameter constructor automatically. However, your base class has no such constructor, so it throws an error at you.

      Comment

      • SpecialKay
        New Member
        • Mar 2008
        • 109

        #4
        Solved, Much thanks. Im a noob!

        Comment

        Working...