Java using array outside main method

73 views
Skip to first unread message

Jack

unread,
Jun 14, 2011, 11:12:03 PM6/14/11
to BYU CS 142 (Spring 2011) [McCarthy]
I am stuck at this problem for a week.

I tried to declare an array outside the main method

public class XXX {
public static Array [] newarray = new newarray [20];{

newarray [0] = new Array ("1","1");
//declaring array up to 20
}

public static void main(String args[]){
System.out.println(newarray[0]);} // i cannot
retrieve the array in main method.



The output shows the newarray[0] = null. What did i do wrong here?

P.S.: assuming Array.java has appropriate constructor, setter and
getter.

Jack

Jay McCarthy

unread,
Jun 14, 2011, 11:35:27 PM6/14/11
to byu-cs-jm-14...@googlegroups.com
I cannot help unless there is an actual program. This text is not a program.

2011/6/15 Jack <jackal...@hotmail.com>:

--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Reply all
Reply to author
Forward
0 new messages