What is a class in Java?
A blueprint or template used to create objects.
What is the purpose of a constructor?
To initialize an object’s instance variables when the object is created.
What is the default value of an int instance variable?
0
What access modifier prevents direct access to instance variables from outside the class?
private
When should a method be declared public?
When it needs to be accessed by code outside the class.
What is an object?
An instance of a class that has its own set of instance variables.
What are the two unique things that identify a constructor in a class?
It has the same name as the class and no return type.
What is the default value of a boolean instance variable?
false
What happens if code tries to directly access a private instance variable?
An error occurs.
When should instance variables be private?
Always!
What keyword is required to create an object from a class?
new
What happens when a class has no constructor written?
Java automatically provides a default constructor.
What is the default value of a String instance variable?
null
Why are instance variables usually declared private?
To protect data and prevent unintended changes.
Why is directly modifying another class’s instance variables considered bad design?
It breaks encapsulation and can cause bugs or invalid data.
What does this line of code do?
Student s1 = new Student();
Creates a new Student object and assigns it to reference variable s1.
What does the default constructor do?
It initializes instance variables to default values.
Why can having an object as an instance variable cause problems?
If we assign an existing object as an instance variable, there are now multiple ways to access it.
What is encapsulation?
Bundling data and methods together while restricting direct access to data.
TRIVIA TIME:
What is the proper name for the mineral known as Fool's Gold?
Pyrite
TRIVIA TIME:
What is the only sea in the world without a coastline?
The Sargasso Sea is found in the Atlantic and is bordered by 4 sea currents.
If a class defines a constructor with parameters, what happens to the default constructor?
It is no longer provided automatically and must be written manually if needed.
How can you fix issues with objects used as instance variables?
Create a new location in memory by using the new keyword and getting the values of the attributes using instance methods.
What is abstraction?
Hiding implementation details and exposing only what the user needs to know.
What is the correct way to interact with another class’s private data?
Through public methods that access or change the private instance variables.