• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance doubt

 
Kshitija Mitter
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The illustration of your question is not very clear. Can you elaborate more so that our replies can be more specific ?
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic