Question and answers already passed
2025
T/F A class is a blueprint for a type of Java object - correct answer ✔True
T/F A java object has data and behavior - correct answer ✔True
You can add behavior to an object by adding_____ to the class - correct
answer ✔methods
To make objects easily printable, write a ____ method that returns a text
representation - correct answer ✔toString
A class's ____ creates a new object that may contain initial values for the
fields - correct answer ✔constructor
Fields can be protected from external modification by making them ____ -
correct answer ✔private
T/F private fields can be directly changed from the client code - correct
answer ✔false
T/F A class is an instance of an object. One object can be used to create
many classes - correct answer ✔false
What is the term for having multiple constructors with different parameters -
correct answer ✔overloading
,What is the correct way to create a Name object - correct answer ✔Name n
= new Name("Will", "c", "Smith");
What is the correct way to create a Point object - correct answer ✔Point p =
new Point(2,3);
What what is true about code p1 and p2 with the same points - correct
answer ✔It creates two Point objects with identical data
A Pokémon object (p1) has a damage method. What is the correct way to call
the damage method - correct answer ✔p1.damage();
Methods that change an objects fields are called - correct answer
✔setters/mutators
A BankAccount object (acct) has a computeInterest method. What is the
correct way to call it - correct answer ✔double result =
acct.computeInterest(42);
What is the correct method header for the toString method - correct answer
✔public String toString() {
What is the correct syntax for a constructor for the Book class - correct
answer ✔public Book(String title, String author){
T/F A class may contain multiple constructors - correct answer ✔true
,T/F Constructors may call other constructors("chaining") - correct answer
✔true
T/F You can access fields inside a class's methods - correct answer ✔true
How do you access private fields from client code - correct answer ✔use
getters/setters
T/F A class can have a filed that is a array - correct answer ✔true
What is an instance method - correct answer ✔A method that can be called
using an object
T/F Getters and Setters are instance methods - correct answer ✔true
The Car class will contain two string attributes for a car's make and model.
The class will also contain a constructor.
public class Car
{
/* missing code */
}
Which of the following replacements for /* missing code */ is the most
appropriate implementation of the class?
A)
public String make;
, public String model;
public Car(String myMake, String myModel)
{ /* implementation not shown */ }
B)
public String make;
public String model;
private Car(String myMake, String myModel)
{ /* implementation not shown */ }
C)
private String make;
private String model;
public Car(String myMake, String myModel)
{ /* implementation not shown */ }
D)
public String make;
private String model;
private Car(String myMake, String myModel)
( /* implementation not shown */ }