Thứ Hai, 9 tháng 3, 2015

ADF1 - Inheritance

Make a documentation of this framework by declare some variables of Actor and create some objects of GoJumpActor, JumpGoActor, asign them to the above variables and call them.


Code:

  • Class Interface Moveable:
public interface Moveable
{
    public void Jump();
    
    public void Forward();
}
  • Class abstract Actor:
public abstract class Actor implements Moveable
{
    private Circle face;
    
    public Actor(){
        face = new Circle();
        face.makeVisible();
        face.changeColor("red");
        face.changeSize(50); 
    }
    
    public void Jump(){
        face.slowMoveVertical(-30);
    }
    
    public void Forward(){
        face.slowMoveHorizontal(10);
    }
}
  • Class extend GoJumpActor:
public class GoJumpActor extends Actor
{
    public void GoAndJump(){
        Forward();
        Jump();
    }
}
  • Class extend JumpGoActor:
public class JumpGoActor extends Actor
{
    public void JumpAndGo(){
        Jump();
        Forward();
    }
}

Không có nhận xét nào:

Đăng nhận xét