File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array initialization" Watch "array initialization" New topic

array initialization

vinita Kh
Ranch Hand

Joined: Feb 19, 2002
Posts: 49
class MyClass1
{ static String arr[];
public static void main(String []args)
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!
I agree. Here's the link:
subject: array initialization
jQuery in Action, 3rd edition