Java OCA OCP Practice Question 3218

Question

Which of the following two definitions of Main (when compiled in separate files) will compile without errors?

A.    class Main {
             public synchronized void foo() {}
     }//  w w  w  . j a  va  2 s.  c o m

B.    abstract class Main {
             public synchronized void foo() {}
     }

C.    abstract class Main {
             public abstract synchronized void foo();
     }

D.       interface Main {
              public synchronized void foo();
     }


A. and B.

Note

Abstract methods (in abstract classes or interfaces) cannot be declared synchronized, hence the options C and D are incorrect.




PreviousNext

Related