Results 1 to 4 of 4
Thread: help me for this
- 05-20-2008, 09:53 AM #1
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
help me for this
Which overloaded version program will excuted............
class MyClass{
public void myFun(Object o){
System.out.println("Object version executed");
}
public void myFun(String s){
System.out.println("String version executed");
}
public static void main(String args[]){
MyClass obj = new MyClass();
obj.myFun(null);
}
}
- 05-21-2008, 06:57 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
String version executed.
First think about default values. In both overloaded methods, you are referencing objects(s also an object of String class, not like primitives.) Default values not referring any objects.
So, think about class hierarchy. Object class is the root/main of the class hierarchy. That means every class has Object as superclass. String class also extended Object. That's why you got the above result I mentioned.
Try to remove that overloaded method, second method with argument type String. You get the result as, Object version executed
Hope it's help to you.
- 05-21-2008, 07:30 AM #3
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
thanks
i got it thanks so much
- 05-21-2008, 07:46 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice to here that pal. If you solve this better to mark as solved. :) IF not just keep going as it is. ;)


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks