A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Another question about Array
Wu Wen
Greenhorn
Joined: Oct 14, 2011
Posts: 27
posted
Dec 17, 2011 22:15:43
0
class Test { public static int[ ] getArray() { return null; } public static void main(String[] args) { int index = 1; try { getArray()[index=2]++; //1 } catch (Exception e){ } //empty catch System.out.println("index = " + index); } }
Why it prints out index = 2 instead of throwing an exception at //1 ?
Nitin Surana
Ranch Hand
Joined: Jan 21, 2011
Posts: 129
I like...
posted
Dec 17, 2011 23:36:18
0
It throws an exception, but you have already caught that.
Wu Wen wrote:
catch (Exception e){ } //empty catch
Javin Paul
Ranch Hand
Joined: Oct 15, 2010
Posts: 276
I like...
posted
Dec 18, 2011 00:34:06
0
why are you coding like that, what do you want to
test
?
http://javarevisited.blogspot.com
-
java classpath
-
Java67
-
java hashmap
-
java logging tips
java interview questions
Java Enum Tutorial
O. Ziggy
Ranch Hand
Joined: Oct 02, 2005
Posts: 430
I like...
posted
Dec 18, 2011 05:53:40
0
What exactly does this line do..
getArray()[index=2]++; //1
Abdullah Mamun
Ranch Hand
Joined: Mar 19, 2007
Posts: 99
I like...
posted
Dec 18, 2011 06:25:36
0
1. method getArray() is called.
2. index variable set with value 2.
3. trying to fetch the value of 2nd index of the array that returned by getArray() method which is null and exception occurs.
MooN
O. Ziggy
Ranch Hand
Joined: Oct 02, 2005
Posts: 430
I like...
posted
Dec 18, 2011 06:45:39
0
Thanks
I agree. Here's the link:
http://aspose.com/file-tools
subject: Another question about Array
Similar Threads
one more question on arrays only
Code execution flow
How expression is working
Confuse
Exception Question.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter