super, super()
reference type variable super, constructor super()
super
reference type variable that indicates itself.
exist within instance method(constructor).
distinguish parent members between current members
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
call parent constructor
initialize parent member by calling parent constructor
add constructor in the first line otherwise compiler adds super(); automatically. 모든 생성자는 첫 줄에 다른 생성자를 호출해야한다. 그렇지 않으면 컴파일러가 자동으로 super()를 호출해버린다.
right code below :
default constructor in Point class
must call other constructor in first line
super constructor in Point3D constructor
Last updated
Was this helpful?