자바 복습 - Ex06_상속

혜미·2020년 11월 30일
0

자바 복습

목록 보기
2/3

상속부분 할때 마다 자꾸 다른일로 놓치는 바람에 많이 뒤쳐진 것 같다.
책으로 개념 익히는 것은 쉽게 익힌 것 같았는데 코딩을 해보려니 막상 생각이 나지 않았다.
너무 어려웠다...ㅜㅜ

class Human{
private String name;
private int age;

//	Human(){
//		
//	}
Human(String name,int age){
	this.name = name;
	this.age = age;
}

void display() {
	System.out.println("name:"+name);
	System.out.println("age:"+age);
}

}//Human

class Employee extends Human{
// private String name;
// private int age;
private String workplace;
private String part;

Employee(String name,int age,String workplace,String part){
	//		this.name = name;
	//		this.age = age;
	super(name,age);
	this.workplace = workplace;
	this.part = part;
}

void display() {
	super.display();
	System.out.println("workplace:"+workplace);
	System.out.println("part:"+part);
}

}// Employee

class Teacher extends Employee{
// private String name;
// private int age;
// private String workplace;
// private String part;
private String subject;
Teacher(String name,int age,String workplace,String part,String subject){
super(name,age,workplace,part);
this.subject = subject;
}

void display() {
	super.display();
	System.out.println("subject:"+subject);
}

}// Teacher

public class Ex06_상속 {
public static void main(String[] args) {
Human h = new Human("써니",30);
Employee e = new Employee("웬디",20,"삼성","홍보부");
Teacher t = new Teacher("슬기",40,"중앙고","생활지도부","음악");
// h.name = "써니";

	h.display();
	System.out.println();
	
	e.display();
	System.out.println();
	
	t.display();

}

}

profile
Memory is the driving force of my life.

0개의 댓글