File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Composition Vs Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Composition Vs Inheritance" Watch "Composition Vs Inheritance" New topic

Composition Vs Inheritance

Balakrishna Thati

Joined: Mar 12, 2008
Posts: 23

During Composition discussion, it is mentioned that

In composition, you can change the member objects @ runtime, to dynamically change the behaviour of the program.

Inheritance does not have this flexibility since compiler must place compile time restrictions on classes created with inheritance.

I doesn't understand this concept.

Can any one give an example code illustration this.

Balakrishna Thati
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

Hi Balakrishna! Welcome to javaranch.

I think by TIJ you mean Thinking in Java. Anyways I think this is not related to SCJP as it is more of a general Object Orientation concept which is not tested in SCJP...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Composition Vs Inheritance
It's not a secret anymore!