<추상 클래스>

==Console==

==Console==

 

==Console==

<Interface 인터페이스>

==Console==

==Console==

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.day11;
 
//inetface가 interface 상속 예제
 
import java.util.Scanner;
 
interface FruitA{
    
    String Won = "원";    //public static final 생략
    
    public int getPrice();
    public String gerName();
    
}
 
interface ItemFruit extends FruitA{    //interface가 다른 interface를 상속
    
    public String getItems();    
    
}
 
class Orange implements ItemFruit{    //override 3개 적용(FruitA 2개, ItemFruit 1개)
 
    @Override
    public int getPrice() {
        return 1500;
    }
 
    @Override
    public String gerName() {
        return "오렌지";
    }
 
    @Override
    public String getItems() {
        return "과일";
    }
        
}
 
class Apple implements ItemFruit{
 
    @Override
    public int getPrice() {
        return 2000;
    }
 
    @Override
    public String gerName() {
        return "사과";
    }
 
    @Override
    public String getItems() {
        return "과일";
    }
    
}
 
public class Test7 {
    
    public void packing(ItemFruit ob){    //ItemFruit ob 에 클래스를 받을 수 있음(ex.new Orange를 넣어줌)
        System.out.println(ob.getItems());
        System.out.println(ob.gerName());
        System.out.println(ob.getPrice()+FruitA.Won);
    }
 
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        Test7 t = new Test7();
        
        System.out.print("1.오렌지 2.사과 : ");//1  2
        int ch = sc.nextInt();
        
        if(ch==1){
            t.packing(new Orange());    // ItemFruit ob = new Orange();
            
        }else if(ch==2){
            t.packing(new Apple());        // ItemFruit ob = new Apple();
            
        }
        
        
/*        ItemFruit ob;
        
        ob = new Orange();
        
        System.out.println("----------------");
        
        //ItemFruit ob2;
        ob = new Apple();
        
        System.out.println("----------------");
*/
        /*
         int a;
         a = 10;
         System.out.println(a);
         
         a = 20;
         System.out.println(a);
         
         */
        
    }
 
}
 

==Console==

+ Recent posts