[JAVA] SUPER CLASS

정은아·2022년 7월 18일
0
package ja_0718;

class Super_1
{
	public void display()
	{
		System.out.println("Super_1 class diplay Method~~");
		show();
	}
	
	public void message()
	{
		System.out.println("Super_1 class message method@@@");
	}
	
	void print() 
   	{
		System.out.println("Super_1 class print Method $$$$$");
	}
	
	private void show() 
	{
		System.err.println("Super_1 class show Method #####");
	}
}
public class Method_1 extends Super_1 {
	public static void main(String[] args) {
    
		Method_1 obj_1 = new Method_1();
		
		obj_1.display();
		obj_1.message();
		obj_1.print();
	//	obj_1.show();
	}
}

왜 Obj_1.show에는 각주가 되어있을까요?
show는 private 되어있기 때문입니다. 다른 클래스에서는 사용할 수 없습니다.

그렇다면 show를 출력하기 위해서는 어떻게 해야할까요?
간단합니다! private이 쓰여있는 같은 클래스에서 show();를 써줌으로써 출력할 수 있게하면 됩니다.

같은 package내에서는 출력이 가능합니다.

profile
꾸준함의 가치를 믿는 개발자

0개의 댓글