방치하기

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

홍익대 Java/수업

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

Yi Junho 2009. 7. 23. 14:44
반응형
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