aspose file tools*
The moose likes Beginning Java and the fly likes super keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super keyword" Watch "super keyword" New topic
Author

super keyword

shruthi gowdas
Greenhorn

Joined: Oct 13, 2011
Posts: 4
Hi Guys,

I wanted to know how to access the methods of grandparent class from the child class (when those methods in child class are overridden) using super keyword. Please help.
Eduardo Lomonaco
Greenhorn

Joined: Oct 13, 2011
Posts: 13



This code produces the output This is FatherClass.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

But you can only go "up" one level.
It's impossible for class Child to call the foo() implementation of class GrandFather.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Eduardo Lomonaco
Greenhorn

Joined: Oct 13, 2011
Posts: 13
Right
PS: Father class extends GrandFather class
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Yes, of course
shruthi gowdas
Greenhorn

Joined: Oct 13, 2011
Posts: 4
Eduardo Lomonaco wrote:Right
PS: Father class extends GrandFather class


Thanks guys, But are you sure I cant manipulate anything with super to get the methods of class? Sorry, but i wish there was some answer to that.
Eduardo Lomonaco
Greenhorn

Joined: Oct 13, 2011
Posts: 13
Hey Sruthi,

I'm no so sure what do you mean by "are you sure I cant manipulate anything with super to get the methods of class"

But using Java reflection API you do can get the methods of the superclass or even instantiate the superclass.

This API can be a lil complicated for starters so I would suggest you to check what this returns and then do some research on Reflection API:

shruthi gowdas
Greenhorn

Joined: Oct 13, 2011
Posts: 4
Eduardo Lomonaco wrote:Hey Sruthi,

But using Java reflection API you do can get the methods of the superclass or even instantiate the superclass.

This API can be a lil complicated for starters so I would suggest you to check what this returns and then do some research on Reflection API:



Thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
Welcome to the Ranch Eduardo Lomonaco, but it’s not “lil” please.

Using names like Father for classes is misleading because biological inheritance and computing inheritance are very different.
If you try to use super-to-superclass code, you are violating the rule that a subclass IS-A superclass.
Eduardo Lomonaco
Greenhorn

Joined: Oct 13, 2011
Posts: 13
Ok, sorry! And thank you for the tips.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super keyword