File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance doubt" Watch "Inheritance doubt" New topic
Author

Inheritance doubt

Kshitija Mitter
Greenhorn

Joined: Mar 03, 2008
Posts: 11
Hi,

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
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

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
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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
Sunny Jain
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: http://aspose.com/file-tools
 
subject: Inheritance doubt
 
Similar Threads
Banning concrete inheritance
doubt regarding accessing parent variables
NoSuchBeanDefinitionException in Spring
Inheritance with two Children?
Inheritance in Java