All Flashcards
What is object initialization?
The process of setting up an object's initial state using a constructor.
Explain the concept of abstraction in constructors.
Using constructors without knowing their inner workings, trusting they will set up the object correctly.
Why is the 'new' keyword essential for object creation?
It tells the program to allocate memory for a new object and calls the constructor.
How does Java handle primitives in memory?
Primitives are stored directly as values in memory.
How does Java handle objects in memory?
Objects are stored as references (memory addresses) to the actual object data.
What determines a valid constructor overload?
Different number of parameters or different order of parameter types.
What happens if a constructor is not explicitly defined?
Java provides a default no-argument constructor if no other constructors are defined.
Why should you check for null objects before using them?
To avoid NullPointerException, which causes the program to crash.
What does it mean for a reference variable to be 'null'?
It means the variable does not point to any object in memory.
How does constructor overloading improve code flexibility?
It allows creating objects with different initial states based on available information.
What are the differences between pass-by-value and pass-by-reference?
Pass-by-value: A copy is passed, original value unaffected. | Pass-by-reference: The memory address is passed, original value can be modified.
What are the differences between a default constructor and a parameterized constructor?
Default constructor: No parameters, provides default initialization. | Parameterized constructor: Accepts parameters, allows custom initialization.
What is a constructor?
A special method that creates new objects and sets them up with initial characteristics.
What is the 'new' keyword used for?
Used to call the constructor and create a new object.
What is a parameter list in a constructor?
Values provided to the constructor to initialize the object's attributes.
What is pass-by-value?
A copy of the value is passed to the method; changes inside the method don't affect the original value.
What is pass-by-reference?
A reference (memory address) is passed to the method; changes inside the method do affect the original object.
What is a constructor signature?
The constructor's blueprint, including the class name and the parameter types.
What is constructor overloading?
Having multiple constructors in a class with different parameter lists.
What is a default constructor?
A constructor with no parameters.
What is a null object?
An object that doesn't exist; its reference variable stores 'null'.
What is a NullPointerException?
An error that occurs when you try to call a method on a null object.