Meaningless Drivel is fun!
The moose likes OO, Patterns, UML and Refactoring and the fly likes Composition Vs Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Composition Vs Inheritance" Watch "Composition Vs Inheritance" New topic

Composition Vs Inheritance

prasad bhn

Joined: May 04, 2001
Posts: 28
Can anybody please explain me what is the difference between composition and inheritance.
I would appreciate the help from anybody.
Thanks in advance,
Prasad Bh.

prasad bhuvanam
Laojar Chuger
Ranch Hand

Joined: Dec 20, 2000
Posts: 111
Basically, composition implements the relationship of "has a" and inhertance implements the relationship "is a".
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Composition means that a class is composed of implementations of interfaces instead of inheriting those behaviors from some other class.

"JavaRanch, where the deer and the Certified play" - David O'Meara
David Roberts
Ranch Hand

Joined: Nov 03, 2000
Posts: 142
An example of composition is the attribute reference, ie.
public class A
AnotherClass B = new AnotherClass();
public class A extends B
public class A implements B

David Roberts - SCJP2,MCP

David Roberts - SCJP2,MCP
prasad bhn

Joined: May 04, 2001
Posts: 28
Thanks for the replies friends.
Best Regards,
prasad bhn.
I agree. Here's the link:
subject: Composition Vs Inheritance
It's not a secret anymore!