Java OCA OCP Practice Question 2275

Question

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

A.

class Main {/*  w w  w  .  j ava2  s . co  m*/
    public synchronized void foo() {}
}

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