본문 바로가기

JAVA

다형성 실습2


class Employee{ String name; int salary; public String getEmployee(){ return name + " " + salary; } public Employee(){} public Employee(String name, int salary){ this.name = name; this.salary = salary; } }


 

 


class Manger extends Employee{ String depart; public String getEmployee(){ return name + " " + salary + " " + depart; } public Manger(String name, int salary, String depart ){ super(name, salary); this.depart = depart; } }


 

 


public class Ex06_07 { public static void main(String[] args) { Employee emp = new Employee(); Manger man = new Manger("이영희",4000,""); emp.name = "김철수"; emp.salary = 3000; man.depart = "개발"; System.out.println(emp.getEmployee()); System.out.println(man.getEmployee()); } }


 

 

 

 

 

 

출력물


김철수 3000
이영희 4000 개발