Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Position{
- int x,y;
- Position(int x,int y){
- this.x = x;
- this.y = y;
- }
- int getX() {
- return x;
- }
- int getY() {
- return y;
- }
- void setX(int x) {
- this.x = x;
- }
- void setY(int y) {
- this.y = y;
- }
- }
- class Box{
- Position pos;
- Box(Position p){
- pos = new Position(p);
- }
- Position getPosition(){
- return pos;
- }
- }
- class Room{
- Box box;
- Room(Box box){
- this.box = box;
- }
- }
- public class Sample{
- public static void main(String args[]){
- Position pos = new Position(3,5);
- Box box = new Box(pos);
- pos.setX(5);
- System.out.println( box.getPosition().getX()); // Will return 5.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement