jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Inquisition question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Inquisition question" Watch "Doubt in Inquisition question" New topic
Author

Doubt in Inquisition question

Jehaan Butt
Ranch Hand

Joined: Feb 05, 2009
Posts: 41


Which lines do not compile?
a. Line 1
b. Line 2
c. Line 3
d. Line 4

The answer given is 1 and 3. 3 is obvious - there is no semicolon. But the reason given for line 1 is that "Synchronized is wrong here". What does that mean? Why exactly is synchronized wrong in this statement?


SCJP 6
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The synchronized block cannot be placed outside a method. Furthermore you need to synchronize over an object. System.out.println() does not return an object.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
... you need to synchronize over an object. System.out.println() does not return an object.

To clarify, the syntax needs to be:

Jim... ...


BEE MBA PMP SCJP-6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Inquisition question