profile image

L o a d i n g . . .

 

 

p.330 문제 5번 실행 결과

public class Parent {
	public String nation;
	
	public Parent() {
		this("대한민국");
		System.out.println("Parent() call");
	}

	public Parent(String nation) {
		this.nation = nation;
		System.out.println("Parent(String nation) call");
	}
}
public class Child extends Parent{
	private String name;

	public Child() {
		this("홍길동");
		System.out.println("Child() call");
	}
	
	public Child(String name) {
		this.name = name;
		System.out.println("Child(String name) call");
	}
}
public class ChildEx {
	public static void main(String[] args) {
		Child child = new Child();
		
		System.out.println(child.nation + "사람");
		child.nation = "미국";
		System.out.println(child.nation + "사람");
	}
}

 

 

 

 

 

[Java] 객체 지향 프로그래밍 (OOP)

객체 지향프로그래밍? OOP(Object-Oriented Programming). 개발 시 부품에 해당하는 객체를 만들고 객체를 조립하여 하나의 완성된 프로그램을 만드는 기법 객체 : 물리적으로 존재하거나 추상적으로 생

h-owo-ld.tistory.com

한번 더 읽어보기!

반응형
복사했습니다!