Composition in java can be achieved by using instance variables that refers to other objects.
Example: Car has Engine, or House has Bathroom, a Person has a Job.
Notice that above test program is not affected by any change in the Engine object. If you are looking for code reuse and the relationship between two classes is has-a then you should use composition rather than inheritance.
Biggest benefit of using composition is that we can control the visibility of other object to client classes and reuse only what we need.