Java OCA OCP Practice Question 722

Question

Given:

public class MyClass{ 
    String name; 
    public MyClass (){ 
    } 
} 

Which of the following lines creates an MyClass instance?

Select 1 option

  • A. MyClass e;
  • B. MyClass e = new MyClass ();
  • C. MyClass e = MyClass.new ();
  • D. MyClass e = MyClass ();


Correct Option is  : B

Note

For Option A.

This declares a variable of class MyClass but does not create any object.

For Option B.

Using the new operator is the right way to create an object.




PreviousNext

Related