방치하기

홍대 자바 수업: 클래스 상속 . 본문

홍익대 Java/수업

홍대 자바 수업: 클래스 상속 .

Yi Junho 2009. 7. 23. 14:44
반응형
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
class Shape
{
    String name;
 
    public Shape(String name){
        this.name = name;
    }
     
    public void draw(){
        System.out.println(name +"을 그립니다.");
    }
}
 
class Circle extends Shape
{
    public Circle(String name){
        super(name);
    }
    public void paint(String color){
        System.out.println(color + "입니다 ");
    }
}
 
class Triangle extends Shape
{
    public Triangle(String name){
        super(name);
    }
}
/*
    public void make(Circle cc){
        cc.draw();
    }
*/
class Square extends Shape{
    public Square(String name){
        super(name);
    }
    public void make(Square cc){
        cc.draw();
}
}
 
class ExtendsTest2
{
    public static void main(String[] args)
    {
    /*  Circle c = new Circle("원");
        c.draw();
 
        Triangle tri = new Triangle("세모");
        tri.draw();
 
        Shape s = new Circle("원2");
        s.draw();
*/   
 
        Square squ = new Square("네모");
        squ.make(squ);
        Shape n =new Circle ("원") ;
        ((Circle)n).paint("검정");
 
         
    }
 
     
 
 
}
반응형
Comments