/*
Our application involves many objects that can move. You can define an interface called movable,
containing the signatures of the various movement methods. So define the following abstract methods
to be implemented by the subclasses
moveUp(), moveDown(), moveLeft(), moveRight() & moveUp()
Derive a subclass called MovablePointand provide implementation to all the abstract methods declared in the interface.
*/
public class MianActivity {
public static void main(String[] args) {
MovablePoint m = new MovablePoint(10, 10);
m.moveUp();
m.moveDown();
m.moveLeft();
m.moveRight();
}
}
---------------------------------------------------------------------------
public interface Movable
{
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
}
---------------------------------------------------------------------------
public class MovablePoint implements Movable
{
private int x , y ;
public MovablePoint(int x , int y) {
this.x = x;
this.y = y;
}
@Override
public void moveUp() {
y++;
System.out.println("Point moveUp to point : "+y );
}
@Override
public void moveDown() {
y--;
System.out.println("Point moveDown to point : "+y );
}
@Override
public void moveLeft() {
x--;
System.out.println("Point moveLeft to point : "+x );
}
@Override
public void moveRight() {
x++;
System.out.println("Point moveRight to point : "+x );
}
}
-------------------------------------------------------------------------------

No comments:
Post a Comment