728x90 자바 객체 지향6 [JAVA] ch07-18. 객체 지향 18 public class Ex18 { public static void main(String[] args){ Yoker yoker = new Yoker(); Tablet tablet = new Tablet(); PC pc = new PC(); Audio audio = new Audio(); yoker.buy(tablet); yoker.buy(pc); yoker.buy(audio); yoker.summary(); } } class Audio extends Product{ Audio(){ super(50); } public String toString(){ return "Audio"; } } class Yoker{ int money = 1000; int bonus = 0; Product[] item = new.. JAVA/예제 2017. 8. 22. [JAVA] ch07-11. 객체 지향 11 public class Ex11 { public static void main(String[] args){ FireCar firecar = new FireCar(); firecar.drive(); firecar.stop(); firecar.water(); Car car = firecar; car.drive(); car.stop(); //car.water(); } } class Car{ String color; int door; void drive(){ System.out.println("dreive."); } void stop(){ System.out.println("stop."); } } class FireCar extends Car{ void water(){ System.out.println("wat.. JAVA/예제 2017. 8. 22. [JAVA] ch07-09. 객체 지향 9 public class Ex09 { public static void main(String[] args){ Time time = new Time(23,35,30); System.out.println(time); //time.hour=1; time.setHour(time.getHour()+1); System.out.println(time); } } class Time{ private int hour; private int minute; private int second; Time(int hour, int minute, int second){ this.hour = hour; this.minute = minute; this.second = second; } public int getHour(){ if(hour.. JAVA/예제 2017. 8. 22. [JAVA] ch07-05. 객체 지향 5 public class Ex05 { public static void main(String[] args){ Descendant descendant = new Descendant(); descendant.method(); } } class Descendant extends Parent{ int x = 20; void method(){ System.out.println("x= "+x); System.out.println("this.x= "+this.x); System.out.println("super.x= "+super.x); } } JAVA/예제 2017. 8. 22. [JAVA] ch07-02. 객체 지향 2 public class Ex02 { public static void main(String[] args){ Deck deck = new Deck(); Card card = deck.pick(0); System.out.println(card); deck.shuffle(); card = deck.pick(0); System.out.println(card); } } class Card{ static final int KIND_MAX = 4; //final을 변수에 쓰게되면 상수화. static final int NUM_MAX = 13; static final int SPADE = 4; static final int DIAMOND = 3; static final int HEART = 2; static final.. JAVA/예제 2017. 8. 22. [JAVA] ch07-01. 객체 지향 public class Ex01{// 모든클래스는 상속되어있다. public class Ex01 extends Object 생략됨 public static void main(String[] args){ Ex01 e = new Ex01(); e.paint(); } void paint(){ Point[] p = {new Point(100,100), new Point(140,50), new Point(200,100)}; Triangle t = new Triangle(p); Triangle tp = new Triangle(new Point(100,100), new Point(140,50), new Point(200,100)); Circle c = new Circle(new Point(150,150), 50); .. JAVA/예제 2017. 8. 22. 이전 1 다음 728x90