Classes & Objects
Constructors
Instance Variables
Access Modifiers & Abstraction / Encapsulation
Social Coding
100

What is a class in Java?

A blueprint or template used to create objects.

100

What is the purpose of a constructor?

To initialize an object’s instance variables when the object is created.

100

What is the default value of an int instance variable?

0

100

What access modifier prevents direct access to instance variables from outside the class?

private

100

When should a method be declared public?

When it needs to be accessed by code outside the class.

200

What is an object?

An instance of a class that has its own set of instance variables. 

200

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.

200

What is the default value of a boolean instance variable?

false

200

What happens if code tries to directly access a private instance variable?

An error occurs.

200

When should instance variables be private?

Always! 

300

What keyword is required to create an object from a class?

new

300

What happens when a class has no constructor written?

Java automatically provides a default constructor.

300

What is the default value of a String instance variable?

null

300

Why are instance variables usually declared private?

To protect data and prevent unintended changes.

300

Why is directly modifying another class’s instance variables considered bad design?

It breaks encapsulation and can cause bugs or invalid data.

400

What does this line of code do?

Student s1 = new Student();

Creates a new Student object and assigns it to reference variable s1.

400

What does the default constructor do?

It initializes instance variables to default values.

400

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. 

400

What is encapsulation?

Bundling data and methods together while restricting direct access to data.

400

TRIVIA TIME: 

What is the proper name for the mineral known as Fool's Gold? 

Pyrite

500

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.

500

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.

500

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. 

500

What is abstraction?

Hiding implementation details and exposing only what the user needs to know.

500

What is the correct way to interact with another class’s private data?

Through public methods that access or change the private instance variables. 

M
e
n
u