Java OCA OCP Practice Question 1374

Question

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

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

   final void Main() {
   }/*from ww  w .  java  2  s . c  om*/

   static void f() {
      k = j++;
   }
   
   public static void main() {
      
   }
}

Select 2 options

  • A. The class Main cannot be declared abstract.
  • B. The variable j cannot be declared transient.
  • C. The variable k cannot be declared synchronized.
  • D. The constructor Main( ) cannot be declared final.
  • E. The method f( ) cannot be declared static.


Correct Options are  : C E

Note

After adding a return type, the method cannot be a constructor.

The constructors are not inherited, and so it doesn't make sense to mark them as final.

It is illegal to mark a constructor as final.

So there is no question of overriding them.

Static methods cannot refer to non-static/instance members.




PreviousNext

Related