aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array initialization" Watch "array initialization" New topic
Author

array initialization

vinita Kh
Ranch Hand

Joined: Feb 19, 2002
Posts: 49
class MyClass1
{ static String arr[];
public static void main(String []args)
{
System.out.println(arr[0]);
}
}
y thi sgives nullpointerexception, it should be initialized to null & print "null"
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You never created the array! All you have is a pointer to a String array.
Do this:
static String arr[] = new String[1];
And you'll get null as your output.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
vinita Kh
Ranch Hand

Joined: Feb 19, 2002
Posts: 49
oops!! silly question.
Thanks Paul!
Vinita
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array initialization