guess the error/exception generated in this code: //code 1 ublic class Base{ 2: 3: int array[]; 4: 5: private void test() { 6: System.out.println("Value is: " + array[0]); 7: } 8: 9: static public void main(String[] a) { 10: new Base().test(); 11: } 12: } //code end i wasn't exactly expecting this exception. any comments....
Val Dra
Ranch Hand
Joined: Jan 26, 2001
Posts: 439
posted
0
Right now i can think of 2 exceptions one is ArrayIndexOutOfBounds and the other one is can't call that method because void type does not return a value.
Val SCJP <BR>going for SCJD
Val Dra
Ranch Hand
Joined: Jan 26, 2001
Posts: 439
posted
0
oh another one is static is before public , don't know about that type of error though
Val Dra
Ranch Hand
Joined: Jan 26, 2001
Posts: 439
posted
0
scratch my previouse replys to this didn't look well you'll get an error saying that it's not been initilized so the reference is null since arrays are considered to be objects in java .
Lori Battey
Ranch Hand
Joined: May 17, 2000
Posts: 37
posted
0
Problem I see is that the array doesn't know it's size...
Lori Battey<br />SCJP2
Anshuman Acharya
Ranch Hand
Joined: Jan 19, 2001
Posts: 144
posted
0
well val got it! it is a NullPointerException... well done, val! if you did it without the compiling...
Anshuman Acharya
Ranch Hand
Joined: Jan 19, 2001
Posts: 144
posted
0
I think that this error comes coz in line 6 the toString() method of the array[0] is called but since it is a null... i was just curious about what other exceptions/errors can be thrown in different operations with uninitialized arrays... any comments?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.