Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter05 : constructor 본문

JAVA/chapter13_inheritance_annotation

chapter05 : constructor

GAWON 2023. 5. 26. 18:37
package org.joonzis.ex;
/*
 * super
 * 
 * 1. 자식 클래스가 알고있는 부모 클래스의 참조
 * 2. 사용 방법
 * 		1) super.필드			: 부모 클래스 필드 사용
 * 		2) super.메소드()			: 부모 클래스 메소드 사용
 * 		3) super()				: 부모 클래스의 생성자 사용
 */
class Animal{
	String name;
	public Animal() {}
	public Animal(String name) {
		this.name = name;
	}
}
class Dog extends Animal{
	String personName;
	public Dog(String personName) {
		super();
		this.personName = personName;
	}
	public Dog(String name, String personName) {
		super(name);
		this.personName = personName;
	}
	void whoAmI() {
		System.out.println("내 이름은 " + name + "이고, 주인은 " + personName + "입니다.");
	}
}
public class Ex05_Constructor {
	public static void main(String[] args) {
		
		Dog dog = new Dog("김씨");
		dog.whoAmI();
		
		System.out.println("----------------------");
		
		Dog dog2 = new Dog("김쿠키", "옆집 아주머니");
		dog2.whoAmI();
		
	}
}

'JAVA > chapter13_inheritance_annotation' 카테고리의 다른 글

Test . inheritance  (0) 2023.05.26
chapter04 : constructor  (0) 2023.05.26
chapter03 : inheritance  (0) 2023.05.26
chapter02 : inheritance  (0) 2023.05.26
chapter01 : inheritance  (0) 2023.05.26