• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

doubt regarding accessing parent variables

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
parent{}
child1 extends parent{}
child2 extends child1()

there is same method in both parent and child1 with same name and signature and method is not static.then can i call the method in parent
by using this :
((parent)this.)methodname();

if the method is not static then it is not possible to access the method in parent from child2.am i right?please clear my doubt.
 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Child2 will directly inherit from Child1 and yes you can not directly use the one defined in the Parent class (if not static).
In fact, you only can access the one defined in Parent using a Parent reference to a Parent object(Instantiated in Child2, as an example)!

And by saying ((Parent)this).someMethod(); you are polymorphically referring to Child2, and as far as Child2 is using the version defined in Child1, the same functionality will be used.

I hope that i have cleared your doubts ...

Best of luck ...
 
shreya prabhu
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am sorry i mean in the first case methods are static.
 
reply
    Bookmark Topic Watch Topic
  • New Topic