U E D R , A S I H C RSS

Java Study2004/클래스상속

. 는 문 . 보를 동 를 명.
(superclass)를 (subclass)를 . .
받는. . . 는 Object . 모 받는. 보를 .
대부 보를 . 를 들 Button 만들 Button . 따 Button .
subclassing부른.

만들

를 만들 , 만들 . 만들 는 몇 .
  • 보를 .
  • 를 바 를 바 . 따 .
를 들 Motorcycle Car를 만 . Car Motorcycle . . . 면, Object Vehicle를 만들 는 방 PersonPoweredVehicle EnginePoweredVehicle 를 만들 . EnginePoweredVehicle 는 Motorcycle, Car, Truck등등 . 면 make color Vehicle .

를 만들면, . 따 릿 보를 .
. . . 바는 . .
? . . 바 복(overriding) 부르는 .

Point

  • x,y 받는
  • x,y
  • x 는 메, 는 메
  • y 는 메, 는 메

  • ~cpp 
     
    import javax.swing.JOptionPane;
    
    public class Point {
    
    	private int x;
    
    	private int y;
    
    	public Point() {
    
    	}
    
    	public Point(int aX, int aY) { // .
    		this.x = aX;
    		y = aY;		
    	}
    
    	public int getX() {
    		return x;
    	}
    
    	public int getY() {
    		return y;
    	}
    
    	public void setX(int Ax) {
    		x = Ax;
    	}
    
    	public void setY(int Ay) {
    		y = Ay;
    	}
    
    	public String getName() {
    		return "Point";
    	}
    
    	public void Say(String str) {
    		JOptionPane.showMessageDialog(null, str);
    	}
    
    	public void Say(int temp) {
    		String str = Integer.toString(temp);
    
    		JOptionPane.showMessageDialog(null, str);
    	}
    
    	public static void main(String[] args) {
    		Point P1 = new Point(20,20);
    		Point P2 = new Point(10,10);
    		//RECTANGLE
    		Rectangle p = new Rectangle(P1,P2);
    //		System.out.println(p.getArea());
    		//circle
    		Circle c = new Circle(P1,P2);
    		System.out.println(c.getArea());
    	}	
    }
     

Shape

  • x,y, x,y
  • 는 메


~cpp 
public class Shape {
	protected Point left_top;
	protected Point right_bottom;
	public String name;
	
	public Shape()
	{
		
	}
	public  Shape ( Point p1 , Point p2)
	{
		left_top =	p1;
		right_bottom = p2;
		name = "Shape";
	}
	public Shape ( int x1, int y1, int x2, int y2)
	{
		this.left_top = new Point(x1,y1);
		this.right_bottom = new Point( x2,y2 );
		name = "Shape";
	}
	
	public double getArea()
	{
		return 0;
	}
	public String getName()
	{
		return name;
	}
}

Circle

~cpp public class Circle extends Shape {

	private double radius;

	public Circle() {

	}

	public Circle(Point p1, Point p2) {
		super(p1, p2);
		name = "Circle";
	}

	public Circle(int x1, int y1, int x2, int y2) {
		super(x1, y1, x2, y2);
		name = "Circle";
	}

	public double getArea() {
		if(Math.abs(left_top.getX()-right_bottom.getX()) >= Math.abs(left_top.getY()-right_bottom.getY()))
			radius = Math.abs(left_top.getY()-right_bottom.getY());
		else
			radius = Math.abs(left_top.getX()-right_bottom.getX());
		return Math.PI * radius * radius;
	}

	public String getName() {
		return super.getName();
	}
}

Rectangle

~cpp public class Rectangle extends Shape {
	//right_bottom
	//Point left_top
	
	public Rectangle() {

	}

	public Rectangle(Point P1, Point P2) {
		super(P1, P2);
		name = "Rectangle";
	}

	public Rectangle(int x1, int y1, int x2, int y2) {
		super(x1, y1, x2, y2);
		name = "Rectangle";
	}

	public double getArea() {
		return Math.abs(right_bottom.getX()-left_top.getX()) * Math.abs(left_top.getY()-right_bottom.getY());		
	}

}

  • Unit
    • HP, , (, , 무브, ),
    • , , 무브, (를 바)
    • 면 HP ( ) (ex public void underattack(int aAttackPoint) )

  • 롯(Unit )
    • HP 100, 10,
    • 100
  • (Unit )
    • HP 150, 20,
    • 150
  • 마리, 마리.
  • .

  • java 는 디 ?? 디 데. -
    • 모르 ; --iruril
      • : type functionName( type A1, type A2, A3 = 0 ); .
  • super() 부모 ?? --

    • 를들면 circle getName 메 super.getName() --iruril
      • ~^^
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:32
Processing time 0.0228 sec