File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes about inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about inheritance" Watch "about inheritance" New topic

about inheritance

vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
hello guys,
what is the advantage of inheriting a parent class A compared to creating a new object of class A if we want to use class A's method? Is it because of method overriding?

I'm not available, my BF's name is WORK.
ak pillai
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
You can achieve code reuse in two ways:

1. implementation-inheritance (Gives you polymorphism as well)
2. composition (Can get polymorphism by using interface-inheritance)

Inheritance allows you to have a default behaviour in your parent class and subclasses can override this default behaviour. Implementation-Inheritance strongly couple classes together. So should favour interface inheritance with composition for reuse over implementation inheritance.

For more details refer Q8-Q10 on free sample PDF download at

java j2ee job interview questions with answers | Learn the core concepts and the key areas
I agree. Here's the link:
subject: about inheritance
It's not a secret anymore!