In a class, instance variables are typically ___ and methods are typically ___.
What is private and public?
A constructor's return type is always this
Constructors don't have a return type
What does void mean?
Void means that there is no return type
This scale is used to measure the magnitude of earthquakes.
The Richter scale
Instance variables declared private can only be accessed directly from here.
Within the same class
What are the two ways you can initialize instance variables
You can use the this. keyword or you can set the instance variable equal to the parameter variable name in the constructor header
What access modifier do you want to make most of your methods and why?
Public, so you can access them in other classes.
In computing, what does “CPU” stand for?
Central Processing unit
What is the default value of a boolean instance variable
false
If you don't make a constructor in java what would happen?
the compiler will automatically provide a default, no-argument constructor.
The name of a method you can include in your class in order to return a pre-defined string when an instance of the class is directly called (ex: print(object)).
What is toString?
Who are the two quarterbacks playing in the upcoming super bowl?
Sam Darnold and Drake maye
Name two types of methods you can create that allow you to manipulate private instance variables in another class
Getters/setters, accessors/mutators
what is it called when you have multiple constructors in one class ?
constructor overloading. A class can have multiple constructors that differ in the number and/or type of their parameters.
What is the primary purpose of a getter method?
Getter methods allow outside code to read private instance variables without directly accessing them. This maintains encapsulation while still making data available when needed.
What is the chemical symbol for the 115th element and what is it called?
Mc, Moscovium
Which of the following best describes encapsulation?
A. Combining multiple classes into one file
B. Allowing data to be accessed directly for efficiency
C. Hiding internal data while providing controlled access through methods
D. Sharing variables between objects automatically
C Encapsulation is the principle of hiding a class’s internal data and exposing it only through controlled methods (such as getters and setters). This protects data from unintended changes and improves program reliability.
Consider the following classes:
public class Engine
{
private int horsepower;
public Engine(int hp)
{
horsepower = hp;
}
}
public class Truck
{
private Engine eng;
public Truck(Engine e)
{
eng = e;
}
}
What is a potential issue with the Truck constructor?
A. It makes an unnecessary copy of the Engine
B. It allows outside code to modify eng through the original Engine reference
C. It prevents the engine from being accessed
D. It causes a memory leak
B The Truck constructor assigns the Engine reference directly to the instance variable. This means external code that still has a reference to the original Engine object can modify it, which also affects the Truck. This is a common encapsulation issue involving object references.
Which class diagram best follows good encapsulation principles for a Movie class?
The class stores a movie’s title and rating, and both values must be readable from outside the class.
A.
+ title : String
+ rating : int
+ getTitle() : String
+ getRating() : int
B.
- title : String
- rating : int
+ getTitle() : String
+ getRating() : int
C.
- title : String
- rating : int
- getTitle() : String
- getRating() : int
D.
+ title : String
+ rating : int
- getTitle() : String
- getRating() : int
B. title and rating are private as denoted by the "-" sing. getTitle() and getRating() are public as denoted by the "+" sign.
Name at least one of the two teams that won a Super Bowl in their own stadium.
Tampa Bay Bucs, Los Angeles Rams