This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes null variable casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null variable casting " Watch "null variable casting " New topic
Author

null variable casting

deenbandhu prasad
Greenhorn

Joined: Feb 21, 2008
Posts: 9
public class Test1{
static void method(Object obj){
System.out.println("Object");
}
static void method(String str){
System.out.println("String");
}
public static void main(String args[]){
method(null);
}
}

The output of above program is "String". Can some one explain how is java is handling "null" variable and casting is to String and not object.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think this FAQ will help you.


[My Blog]
All roads lead to JavaRanch
deenbandhu prasad
Greenhorn

Joined: Feb 21, 2008
Posts: 9
Thanks a ton.. it did helped.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: null variable casting