목록JAVA/chapter16_polymorphism (5)
WON.dev
Q1.Test01.java Employee 클래스필드 : String name, String dept 메소드 : Constructor, int pay(), void output() SalaryWorker 클래스필드 : int salary 메소드 : Constructor, int pay(), void output() SalesWorker 클래스필드 : int salesVolume, double salesIncentive --> 인센티브 비율(1000이상 10%, 500이상 5% 나머지 1%) 메소드 : Constructor, int pay(), void output(), int salesPay(), void setSalesVolume(salesVolume), void setSalesIncentive(sal..
package org.joonzis.ex; class Person{ public void eat(String food) { System.out.println(food + "먹는다"); } public void sleep() { System.out.println("잔다"); } } class Student extends Person{ public void study() { System.out.println("공부한다."); } } class Worker extends Person{ public void work() { System.out.println("일한다."); } } public class Ex04_polymorphism { public static void main(String[] args) { ..
package org.joonzis.ex; class Animal{ public void move() {} } class Dog extends Animal{ @Override public void move() { System.out.println("강아지 달린다."); } } class Dolphin extends Animal{ @Override public void move() { System.out.println("돌고래 헤엄친다."); } } class Eagle extends Animal{ @Override public void move() { System.out.println("독수리 움직이고."); } public void fly() { System.out.println("난다."); } } ..
package org.joonzis.ex; class Shape{ // 의미 없는 메소드(자식들이 사용하기 위해 만들어놓음) public double calcArea() { return 0; } } class Rect extends Shape{ private int width, height; public Rect(int width, int height) { this.width = width; this.height = height; } @Override public double calcArea() { return width * height; } } class Triangle extends Shape{ private int width, height; public Triangle(int width, int h..
package org.joonzis.ex; class Product{ public void info() { System.out.println("Product"); } } class Computer extends Product{ @Override public void info() { System.out.println("Computer"); } } class Notebook extends Computer{ @Override public void info() { System.out.println("Notebook"); } } public class Ex01_polymorphism { public static void main(String[] args) { // 업캐스팅 // 부모(Product)