• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Consider this code

 
sandhi mridul
Ranch Hand
Posts: 71
  • 0
  • 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 ]
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is t2f() and t3f()?

Henry
 
sandhi mridul
Ranch Hand
Posts: 71
  • 0
  • 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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic