Java OCA OCP Practice Question 178

Question

How many instance initializers are in this code?

1:  public class MyClass { 
2:     { System.out.println(); } 
3:     public MyClass () { 
4:        System.out.println(); 
5:     } 
6:     static { System.out.println(); } 
7:     { System.out.println(); } 
8:  } 
     ? 
  • A. None
  • B. One
  • C. Two
  • D. Three


C.

Note

Lines 2 and 7 illustrate instance initializers.

Line 6 is a static initializer.

Lines 3-5 are a constructor.




PreviousNext

Related