My footsteps

참조변수 Super 본문

예습/code

참조변수 Super

밀김 2023. 1. 13. 10:34
728x90

 

 

 

public class Over {
	public static void main(String[] args) {
		Child C = new Child();
		C.String();
	}

}

class Parent {
	int x = 10;
	}

class Child extends Parent{
	int x = 20;
	
	void String() { //굳이 매서드를 만들어서 main매서드 에서 호출하는 이유는,main"매서드"이기 때문에 class는 직접호출할수없다.
		System.out.println("this.x = "+this.x);
		System.out.println("super.x = "+super.x);
	}
}

 

 

 

 

728x90

'예습 > code' 카테고리의 다른 글

참조변수 형변환  (0) 2023.01.13
접근제어자  (0) 2023.01.13
오버라이딩  (0) 2023.01.13
단일상속  (0) 2023.01.13
포함  (0) 2023.01.13