Java OCA OCP Practice Question 1720

Question

What, if anything, is wrong with the following code?.

abstract class Main {
  transient int j;
  synchronized int k;

  final void Main() {}

  static void f() {}
 }

Select the one correct answer.

  • (a) The class Main cannot be declared abstract.
  • (b) The field j cannot be declared transient.
  • (c) The field k cannot be declared synchronized.
  • (d) The method Main() cannot be declared final.
  • (e) The method f() cannot be declared static.
  • (f) Nothing is wrong with the code; it will compile successfully.


(c)

Note

A class can be declared abstract even if it does not declare any abstract methods.

The variable k cannot be declared synchronized.

Only methods and blocks can be synchronized.




PreviousNext

Related