This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method..

 
xie li
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 public class Test {
2 public static void add3 (Integer i) {
3 int val = i.intValue();
4 val += 3;
5 i = new Integer(val);
6 }
7
8 public static void main(String args[]) {
9 Integer i = new Integer(0);
10 add3(i);
11 System.out.println(i.intValue()); 12 } 13 } What is the result?

A. 0

B. 3

C. Compilation fails.

D. An exception is thrown at runtime.
 
Devi Sri
Ranch Hand
Posts: 114
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer: A. 0
 
Cheenu Subramanian
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When u pass arguments to a method, only a copy of the reference /value is passed. so changes to the reference/value will not reflect in the calling method. But changes to the values referred by the reference will be reflected. Hope thats not too confusing
 
vipul patel
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xie,

Just remember that everything is passed by value. There is nothing like pointers.

As K&B says, and I love it. "Java is not C++". saying such thing by yourself will really(!) convience yourself to think java code seperately than C++ code.

By the way, output is 0. so option A is right.
 
xie li
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic