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 Inheritance doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance doubt" Watch "Inheritance doubt" New topic

Inheritance doubt

Kshitija Mitter

Joined: Mar 03, 2008
Posts: 11

Reading thru the inheritance basics.. Got a query on the same.

In the following scenario can child1 access child2 methods?

class Parent - Parent Class

Parent has child classes, viz: child1, child2, ...
[ May 28, 2008: Message edited by: Kshitija Mitter ]
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

I'm not sure i follow your question...

if you're saying

class Parent{}
class child1 extends Parent{}
class child2 extends Parent{}

then no. child2 knows nothing about child1. however, both child1 and child 2 know about Parent's methods.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

The illustration of your question is not very clear. Can you elaborate more so that our replies can be more specific ?

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Deepak Chopra
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

I think Fred got it right..
In your case, child1 doesn't know about child2. the only way to access child2 method in child1 is through Composition. i.e; declare one object of type child2.

I hope it will work.

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
I agree. Here's the link:
subject: Inheritance doubt
It's not a secret anymore!