• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inheritance classification

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would like to know if there any way by which the child class can differentiate between inherited and implemented methods of its parent class.

i.e. when class C extends class B extends class A.

There are three possible cases by which class C inherits method m1() :

a. Method m1() implemented in class A is just inherited by class B and is further passed to the next generation of class C.
b. Method m1() is implemented in class A and funcionality is overridden in class B.
c. Method m1() is not defined in class A but is defined in class B.

Is there any way for class C to differentiate the above cases. Although this might not have any practical usage but I am curious to know. For eg. when we use an IDE like jcreator etc. and try to access an objects functions it popsup the avlbl functions after pressing '.' but those functions that are specifically implemented by the object are boldfaced so wld like to know more abt this.

Regards JPraveen.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by JPraveen Kumar:
Hi,

I would like to know if there any way by which the child class can differentiate between inherited and implemented methods of its parent class.

i.e. when class C extends class B extends class A.

There are three possible cases by which class C inherits method m1() :

a. Method m1() implemented in class A is just inherited by class B and is further passed to the next generation of class C.
b. Method m1() is implemented in class A and funcionality is overridden in class B.
c. Method m1() is not defined in class A but is defined in class B.

Is there any way for class C to differentiate the above cases. Although this might not have any practical usage but I am curious to know. For eg. when we use an IDE like jcreator etc. and try to access an objects functions it popsup the avlbl functions after pressing '.' but those functions that are specifically implemented by the object are boldfaced so wld like to know more abt this.



Ofcourse you can do it .. This is generally achieved using the <java.lang.reflect> package. IDEs (which I dont use) use this package to do all the highlighting, bold facing and many other GUIsh things. Incase reflection is NEW to you .. simply .. "reflection is the ability of a software to analyse itself."

I am not sure whether reflection is tested in SCJP, but this is a very useful package in cases where you dont have access to the source Java files, but you can analyse the classes using this package. Hope this helps. Its been a long time since I did any reflection, but you should get some help from the following URLs

http://java.sun.com/docs/books/tutorial/reflect/
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
M M V, thanks for joining into the forum. However, please take a few minutes to read our JavaRanch Naming Policy and change your displayed name accordingly.

Thanks
-Barry
 
reply
    Bookmark Topic Watch Topic
  • New Topic