Hi,
I'm a bit confused...
If you can simply add a "extends X" keyword on top to get access to all of the other classes variables and methods
why do the
TheClass x = new TheClass();
x.something();
etc?
Printable View
Hi,
I'm a bit confused...
If you can simply add a "extends X" keyword on top to get access to all of the other classes variables and methods
why do the
TheClass x = new TheClass();
x.something();
etc?
extends defines identity, also known as an is-A relationship.
You do the other thing (also known as composition) when you just want the behaviour without changing the type of the guy providing the behaviour.
Generally, it is easier to acquire/change behaviour than it is to change identity.