aspose file tools*
The moose likes Java in General and the fly likes Overirding issue when the classes are in 2 diff packages! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overirding issue when the classes are in 2 diff packages!" Watch "Overirding issue when the classes are in 2 diff packages!" New topic
Author

Overirding issue when the classes are in 2 diff packages!

Pavan Dittakavi
Greenhorn

Joined: Aug 13, 2010
Posts: 2
Hi All,

I have a method in a Class DateButton. And Im currently working on another Class MyApplication. Now the DateButton class is too generic to modify. And I need to modify a method in it. So, Im trying to override that method as follows in MyApplication.

I would like to mention that each of these two files is in a seperate package. Also they are no way related!.Also the DateButton class extends AbstractDateButton.So, obviously, the call-->super.postUp() of DateButton is calling the one in the AbstractDateButton class.

But,when Im trying to overlaod this method in the MyApplication class..the "super.postUp()" method is actually calling the method in the DateButton; Now my issue gets resolved if I somehow manage to call the method in AbstractDateButton.

Here is my code!

Please do let me know what I am missing here...also please let me know why this call "super.postUp()" in MyApplication is calling the one in DateButton and not the one in AbstractDateButton.

Regards,
Pavan.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
What you've created here is a subclass of DateButton. So calling super.postUp() calls the postUp() method in DateButton.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Pavan Dittakavi wrote:Please do let me know what I am missing here...also please let me know why this call "super.postUp()" in MyApplication is calling the one in DateButton and not the one in AbstractDateButton.

Like Garret said, your anonymous class extens DateButton. So that's it's its parent, and not AbstractDateButton. To call a super super method isn't allowed in Java (because of encapsulation). You could only provide a method in DateButton like 'superPostUp()'. Look at the example below:


It prints:
A
AB
ABC
AD


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

or you can call super.postUp from the DateButton class' postUp method ... like this




hope this'll work for you ...


http://plainoldjavaobject.blogspot.in
Pavan Dittakavi
Greenhorn

Joined: Aug 13, 2010
Posts: 2
Hi Lalit,

I could have well done that!. But the thing is, if I try to call the "postUp" method in the DateButton class..the functionality gets hampered!!. I mean there is additional code in the DateButton class and if it gets processed then we will be having some issues.

Regards,
Pavan.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
And welcome to JavaRanch
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Sometimes I hate it, when I'm ignored. Pavan, did you understand the example?
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

ok ... well in that case you could use some sort of conditional processing if it is possible or
you can just overload that method pushUp() in your DateButton class like this


void pushUp(boolean) and call super.pushUp() from inside that while calling the overloaded method from your MyApplication class

"Peter's example is an option too"

Lalit ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overirding issue when the classes are in 2 diff packages!