I have a class with objects
Now i want to call a function from Box and Toy object from outside of the Container class
class Container
{
Box box1 = new Box();
Toy toy1 = new Toy();
public void open()
{
box1.open();
}
public void play()
{
toy1.play();
}
}
How can i avoid recreating the methods and just sharing the methods with the Container class.
I can not use inheritance because I have 2 or more objects.
You can do it as follows.
Then you can access methods of Box and Toy class outside of the Container.