Java OCA OCP Practice Question 239

Question

Given the following code, fill in the blank to have the code print MyClass.

public class MyClass { 
        public MyClass() { 
           System.out.println("MyClass"); 
        } 
        public static void main(String[] slam) { 
             _____________
        } 
} 
  • A. MyClass;
  • B. MyClass();
  • C. new MyClass;
  • D. new MyClass();


D.

Note

In order to call a constructor, you must use the new keyword.

It cannot be called as if it was a normal method.

This rules out Options A and B.

Option C is incorrect because the parentheses are required.




PreviousNext

Related