This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread output

 
sumit kothalikar
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see the following code


and the output is

[I@42e816
[I@42e816
[I@42e816
[I@42e816
[I@42e816
[I@42e816
[I@42e816

Why the output is not
2
34
5
6
7
8
9

Is it because i have marked mt ref variable as final or is it because m1() method is synchronized.
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In m1 method, you are displaying the array a in the loop not the loop variable x. Since a is a local array, there are no synchronization issues. Each call to the m1 method will have a separate copy of a array...
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it because i have marked mt ref variable as final or is it because m1() method is synchronized.

None of those. Closely check what exactly you are printing inside the "System.out.." statement
 
sumit kothalikar
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Vijitha


Vijitha Kumara wrote:
None of those. Closely check what exactly you are printing inside the "System.out.." statement


you are right i am printing array object reference.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic