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 ?
- A.
Person obj = new Person();
- B.
new Person obj = new Person ();
- C.
Person obj = new();
- 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.