Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Consider this code

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



output:-T2,T3,T2,T2,T3,T2
What is going on in this code?
Please help me with this.

Thanks
Sandhi
[ March 14, 2008: Message edited by: sandhi mridul ]
 
author
Posts: 23835
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is t2f() and t3f()?

Henry
 
sandhi mridul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry Henry.
While typing I missed the imp thing -the dot operator.
I have corrected it.

Thanks
But still need the ans
 
Henry Wong
author
Posts: 23835
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you do know that you are not overriding the f() method right? You are overloading it. With overloading, the type of reference is actually important -- as it is used to determine the method to call. And since the method is determined at compile time, the type of reference is important.

A T2 reference only has a single f() method, while a T3 reference has two overloaded f() methods. Meaning, it doesn't matter whether you pass a T2 or T3 reference to a T2 reference, it will be treated as a T2 reference. But it does matter whether you pass a T2 or T3 reference to a T3 reference, as it will be used to determine which overloaded method to call.

t2.f(t3); --> T2, because a T2 reference only has a single f() method
t3.f(t3); --> T3, because the overloaded f(T3) method is called
t2.f(t2); --> T2, because a T2 reference only has a single f() method
t3.f(t2); --> T2, because the overloaded f(T2) method is called
t3.f((T3)t2); --> T3, because the overloaded f(T3) method is called
t2.f((T3)t3); --> T2, because a T2 reference only has a single f() method

Henry
 
sandhi mridul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!