File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null variable casting
 
Similar Threads
Null Pointer Exception
mock exam question
why this outout
instanceof
Some doubt about Method calling