• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overirding issue when the classes are in 2 diff packages!

 
Pavan Dittakavi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you've created here is a subclass of DateButton. So calling super.postUp() calls the postUp() method in DateButton.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or you can call super.postUp from the DateButton class' postUp method ... like this




hope this'll work for you ...
 
Pavan Dittakavi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes I hate it, when I'm ignored. Pavan, did you understand the example?
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic