# super, super()

* **super**

1. reference type variable that indicates itself.
2. exist within instance method(constructor).
3. distinguish **parent members** between current members

```java
class Parent {int x = 10;}

class Child extens Parent {
    int x = 20;
    
    void omethod() {
        System.out.prinln("x=" - x);
        System.out.prinln("this.x=" + this.x);
        System.out.prinln("super.x=" + super.x);
    }
}
```

* super() : parent constructor

1. call parent constructor
2. initialize parent member by calling parent constructor
3. add constructor in the first line otherwise compiler adds super(); automatically. 모든 생성자는 첫 줄에 다른 생성자를 호출해야한다. 그렇지 않으면 컴파일러가 자동으로 super()를 호출해버린다.

```java
class Point {
    int x,y;
    
    Point() {
        this(0,0);//constructor in first line
    }
    
    Point(int x, int y) {
        
        this.x = x;
        this.y = y;
    }
}
class Point3D extends Point {
    int z;
    
    Point 3D(int x, int y, int z) {
        super(x,y);
        this.z = z;
    }
}

```

```java
class Point{
    int x,y;
    
    Point(int x, int y) {
        //no constructor in first line
        //=>compiler will add super();
        this.x = x;
        this.y = y;
    }
}

class Point3D extends Point {
    int z;
    
    Point3D(int x, int y, int z) {
        super(x,y);//call parent constructor super()
        this.z = z;
        //this.x = x;
        //this.y = y;
        
    }
}
```

right code below :

1. default constructor in Point class
2. must call other constructor in first line
3. super constructor in Point3D constructor

```java
class Point {
    int x;
    int y;
    
    //1. default constructor
    Point() {}
    Point(int x, int y) {
        //2. must call other constructor in first line
        Point(){};
        this.x = x;
        this.y = y;
    }
    
}
class Point3D extends Point {

    int z;
    
    Point3D(int x, int y, int z) {
        
        Point(x,y);
        this.z = z;
    }
    
    
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/java/super-super.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
