1Z0-808 · Question #63
Given the exhibit: public class Student { public String name = ""; public int age = 0; public String major = "Undeclared"; public boolean fulltime = true; public void display() {…
The correct answer is C. Student student1 = new Student(). Option C uses the correct Java syntax for instantiating an object: the new keyword followed by the class constructor call Student(), which allocates memory and initializes the object's fields to their default values. A is wrong because Student student1; only declares a…
Question
Options
- AStudent student1;
- BStudent student1 = Student.new();
- CStudent student1 = new Student();
- DStudent student1 = Student();
How the community answered
(59 responses)- A2% (1)
- B2% (1)
- C90% (53)
- D7% (4)
Explanation
Option C uses the correct Java syntax for instantiating an object: the new keyword followed by the class constructor call Student(), which allocates memory and initializes the object's fields to their default values.
- A is wrong because
Student student1;only declares a reference variable - it doesn't allocate any object, leavingstudent1asnull. - B is wrong because
Student.new()is not valid Java syntax;newis a keyword, not a method you call on a class. - D is wrong because
Student()withoutnewreads like a method call, not object construction - Java requiresnewto invoke a constructor.
Memory tip: Think of new as placing an order - you must say new ClassName() to create something new, otherwise you're just holding an empty label (declaration) or writing nonsense syntax.
Topics
Community Discussion
No community discussion yet for this question.