What does a constructor do when preparing a new object?
It initializes fields or performs setup.
When does a constructor run during object creation?
When the program creates an object with `new` and a matching constructor call.
What must a constructor’s name match?
Its class name.
What return type does a constructor have?
None.
What defines a no-argument constructor?
It has no parameters.
What does a parameterized constructor accept?
Input values.
What does constructor overloading mean?
Creating constructors with different parameter lists.
Which call chains constructors within the same class?
`this()`.
Which call chains constructors across inheritance?
`super()`.
Where must a `this()` or `super()` call appear in a constructor?
Before any other statement.
What does a class describe, and what does each object created from it have?
A class describes structure, and each object has its own state.
What event makes an object eligible for garbage collection?
No live path reaches the object.
Which steps precede object use in an object life cycle?
Class loading, then object creation with `new` and a constructor.
Where are method-call frames and local variables commonly associated?
The stack.
Where are objects generally allocated?
The heap.
When is an object reachable?
When a live reference path leads to it.
When is an object unreachable?
When no live reference path reaches it.
What does garbage-collection eligibility mean about when an object will be collected?
It does not mean the object will be collected immediately.
What must Java programs do with files, sockets, and database connections?
Close them properly.
How does Java manage object memory?
Automatically.
What does `new Student()` assign to `name` in the given class?
`New Student`.
Which constructor runs when the given class evaluates `new Student()`?
`Student()`.
Which modifiers cannot be used to declare a constructor?
`static`, `final`, `abstract`, and `synchronized`.
What should a programmer expect after declaring a custom constructor?
A default constructor should not be expected.
What must a constructor call match?
The number and types of arguments accepted by the constructor.
What is the scope of a variable name?
The part of a program where the name can be accessed.
In `Student s = new Student();`, what does `s` refer to?
The `Student` object created by `new Student()`.
What does assigning `null` to a reference mean?
That reference no longer points to the object.
What does calling `System.gc()` guarantee about collecting a specific object?
It does not guarantee immediate collection.
What common programming error involves calling a method through a null reference?
Calling a method through a null reference.
Answer 12 questions on Java Constructors and Object Lifetime.
1. When does a constructor prepare an object by initializing fields or performing setup?
2. Given `class Student { String name; Student() { name = "New Student"; } }`, what is the result of evaluating `new Student()`?
Go over the full study guide for Java Constructors and Object Lifetime.
Read the study guide →Upload your class notes and Revizly writes your flashcards in about a minute.
Flashcard maker