In Java, which of the following is the correct way to create an object of a…

2025

In Java, which of the following is the correct way to create an object of a class Person ?

  1. A.

    Person obj = new Person();

  2. B.

    new Person obj = new Person ();

  3. C.

    Person obj = new();

  4. D.

    Person new obj = Person ();

Attempted by 47 students.

Show answer & explanation

Correct answer: A

In Java, object instantiation requires the class type followed by a variable name and the new keyword. The correct syntax is Person p = new Person(); which creates an instance of the class.

Explore the full course: Tpsc Assistant Technical Officer