aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Inquisition question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 6588
    
    1

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 - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
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: jrebel
 
subject: Doubt in Inquisition question
 
Similar Threads
q from jiris.com
wait() or notify()??
Array
about threads, using locks of the objects in synchronized blocks
Inquisition mock question by Mark Dechamps