My footsteps
abstract class Unit2{ int x,y; abstract void move(int x,int y); void stop() {System.out.println("멈춤");} } interface Fightable { //인터페이스 매서드 생성 void move(int x,int y); //앞에 public이 다 생략되어있는 상태 void attack(Fightable f); } class Fighter extends Unit2 implements Fightable{ //유닛2를 상속받은 자식 파이터가, 인터페이스인 파이터볼을 구현한다 public void move(int x,int y) { //public을 생략하면 에러뜸. 조상이 퍼블릭인데 자손이 퍼블릭을 떼버리면 제어자 범위가 좁아지는거..
abstract class Plyer{ //추상클래스 Plyer(=미완성 설계도) abstract void play(int pos); //매개변수 有 abstract void stop(); //매개변수 無 //play,stop는 추상매서드라서 구현부 { } 가 없어도 됨 } class AudioPlyer extends Plyer{ //추상클래스 Plyer는 반드시, 자손과 상속관계로 묶여야만 작동시킬수 있다. void play(int pos) {System.out.println(pos+"부터 재생합니다.");} void stop() {System.out.println("멈춤");} } class Ex7_9 { public static void main(String args[]) { //AudioPlyer..
class Product2{ //부모 Product2클래스 생성 int price; int bonusPoint; Product2(int price){ //반환타입이 int형인 변수price를 갖고있는 Product2매서드 this.price = price; //매서드 프라이스의값은 클래스 프라이스와 같다 bonusPoint = (int)(price/10.0); //클래스 프라이스 값을 10.0으로 나누고 그것을 int형으로 반환하는걸 클래스 보너스에 대입 } } class Tv2 extends Product2{ Tv2(){ //매개변수가 없는 매서드 Tv2 super(100); //부모인 프로덕트2 매서드(int price) 에다가 100을 대입 } public String toString() { ret..
class Ex7_8 { public static void main(String args[]) { Buyer b = new Buyer(); //객체 b 생성 b.buy(new Tv1()); b.buy(new Computer()); //b가 가리키는 buy의 값에 tv1,computer객체 대입 → ★★매개변수의 다형성★★ System.out.println(b.money); System.out.println(b.bonusPoint); } } class Product { int price; int bonusPoint; Product(int price) { //반환형식이 int형인 product매서드의 pirce 클래스 this.price = price; //iv와 lv구분(class의 price와 매서드의 ..