Let’s say I have a class named Door
with an attribute that states whether it’s open or closed. Then, there is another class named Person
, that is assigned to that door.
How would you tell the person to open/close the door by changing the value of the attribute in the Door
class with a method in the Person
class?
Advertisement
Answer
You mean something like this?
class Door { public boolean closed = true; } class Person { Door door = new Door(); public void changeDoorState(boolean closed) { door.closed = closed; } }