Super() not working on my extends class

jaimito

I'm pretty new in java and I'm doing a simple program but I don't know why I get an error in my program when I'm try to use super... Does anybody can explain me or what is my error, because it's not accepting super.myCoord() what should I change or add?

  public class myCoord {

    private double coorX, coorY;

    public myCoord(){
        coorX = 1;
        coorY = 1;
    }

    public myCoord(double x,double y){
        coorX =  x;
        coorY = y;
    }

    void setX(double x){
        coorX = x;
    }

    void setY(double y){
        coorY = y;
    }

    double getX(){
        return coorX;
    }

    double getY(){
        return coorY;
    }

    public String toString(){
        String nuevo = "("+coorX+", "+coorY+")";
        return nuevo;
    }

    public class Coord3D extends myCoord{
        private double coorZ;

        Coord3D(){
            super.myCoord(); // ---> I got an error here !!
            coorZ = 1;
        }

        Coord3D(double x, double y, double z){
            super.myCoord(x,y);  ---> Also here !!
            coorZ = z;

        }

        void setZ(double z){
            coorZ = z;
        }

        double getZ(){
            return coorZ;
        }

    }
Prateek

You should call methods, not constructors, using the dot (.) operator. Here you are calling super class' constructor using dot (.).

That's why you are getting errors like these:

The method myCoord() is undefined for the type myCoord

and

The method myCoord(double, double) is undefined for the type myCoord

Use these to call your super constructor: super(); and super(x,y); as shown below.

public class Coord3D extends myCoord {
    private double coorZ;

    Coord3D() {
        super(); // not super.myCoord(); its a constructor call not method call
        coorZ = 1;
    }

    Coord3D(double x, double y, double z) {
        super(x,y);  // not super.myCoord(x,y); its a constructor call not method call
        coorZ = z;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Super() not working on my extends class

From Dev

super keyword without extends to the super class

From Dev

super keyword without extends to the super class

From Dev

Swing - My class extends JTextPane and calling first my append() and then super.setText() add additional line break

From Dev

Extends class with two parameters of super class in Java

From Dev

PHP class, extends database not working

From Dev

Coffeescript tree extends class not working

From Dev

My VIEWS or WIDGETS from XML is not working at java on a class that extends a fragment class

From Dev

Why is my custom HashMap class, which extends HashMap, not properly working for put?

From Dev

Calling overloaded super constructor in ScalaJS class that extends a native class

From Dev

<? extends Class> and <? super Class> in Java - why it works this way?

From Dev

@Value not working inside a class which extends other

From Dev

Why generic type is not applicable for argument extends super class for both?

From Dev

Cannot resolve method super in class which extends ArrayAdapter

From Dev

Clear memory of parent class instance created by calling super/extends

From Dev

Constructing objects that extends a super class that has its own constructor

From Dev

Cannot resolve method super in class which extends ArrayAdapter

From Dev

Autowired not working if used inside class that extends Spring security class

From Dev

Have system not call keyPressed in my class that extends class that implements KeyListener

From Dev

Generics extends and super with ? differencies

From Dev

Implementing extends/super manually

From Dev

springboot data rest not working with super class @MappedSuperclass

From Dev

My findViewById isn't working on 'MainActivity extends FragmentActivity'

From Dev

Why does `Class<T> == Boolean.class` cause a compiler error when `T extends Comparable<? super T>`?

From Dev

cannot implements with the onBindViewHolder in my class extends RecyclerView.Adapter

From Dev

Adding a scrollbar to my JTextArea- class extends JFrame

From Dev

How to find if a class is super class of my class instance

From Dev

How to find if a class is super class of my class instance

From Dev

Java GC: does it ever make sense to call super.finalize() in a class that only extends Object?

Related Related

  1. 1

    Super() not working on my extends class

  2. 2

    super keyword without extends to the super class

  3. 3

    super keyword without extends to the super class

  4. 4

    Swing - My class extends JTextPane and calling first my append() and then super.setText() add additional line break

  5. 5

    Extends class with two parameters of super class in Java

  6. 6

    PHP class, extends database not working

  7. 7

    Coffeescript tree extends class not working

  8. 8

    My VIEWS or WIDGETS from XML is not working at java on a class that extends a fragment class

  9. 9

    Why is my custom HashMap class, which extends HashMap, not properly working for put?

  10. 10

    Calling overloaded super constructor in ScalaJS class that extends a native class

  11. 11

    <? extends Class> and <? super Class> in Java - why it works this way?

  12. 12

    @Value not working inside a class which extends other

  13. 13

    Why generic type is not applicable for argument extends super class for both?

  14. 14

    Cannot resolve method super in class which extends ArrayAdapter

  15. 15

    Clear memory of parent class instance created by calling super/extends

  16. 16

    Constructing objects that extends a super class that has its own constructor

  17. 17

    Cannot resolve method super in class which extends ArrayAdapter

  18. 18

    Autowired not working if used inside class that extends Spring security class

  19. 19

    Have system not call keyPressed in my class that extends class that implements KeyListener

  20. 20

    Generics extends and super with ? differencies

  21. 21

    Implementing extends/super manually

  22. 22

    springboot data rest not working with super class @MappedSuperclass

  23. 23

    My findViewById isn't working on 'MainActivity extends FragmentActivity'

  24. 24

    Why does `Class<T> == Boolean.class` cause a compiler error when `T extends Comparable<? super T>`?

  25. 25

    cannot implements with the onBindViewHolder in my class extends RecyclerView.Adapter

  26. 26

    Adding a scrollbar to my JTextArea- class extends JFrame

  27. 27

    How to find if a class is super class of my class instance

  28. 28

    How to find if a class is super class of my class instance

  29. 29

    Java GC: does it ever make sense to call super.finalize() in a class that only extends Object?

HotTag

Archive