Which of the following best describes the relationship between classes and objects?
An object is an instance of a class.
All methods must return a value.
False
A variable that is declared inside of a method is called ______ variable.
local or instance
What does the keyword this
refer to?
The object the current method is being called on.
A variable declared in one method can have the same name as variable declared in another method.
True
What is the difference between the arguments (or actual parameters) and parameters (or formal parameters)?
Arguments are the values that are passed to method. Parameters are variables that store those values.
Which of the following is a correct class definition of a class name Monkey
, with a public instance variable called business
and a public void
method called seeNoEvil
?
1 2 3 4 5 6 7 8 public class Monkey { public String business; public void seeNoEvil() { System.out.println("Nothing to see here!"); } }
Assume there is a class called Leopard
with a member function called getNumberOfSpots
that takes no arguments and returns an integer value. What would be the correct way to call that method on a Leopard
object called laura
?
1 int numSpot = laura.getNumberOfSpots();
What is the difference between a public and private instance variable?
A public instance variables is accessible outside of its class definition. A private instance variable is only accessible inside its class definition.
Method definitions can be marked as private?
True
Which is the correct way to define a class called LightBulb with an instance variables called wattage, with an accessor method and a mutator method for instance variables?
1 2 3 4 5 6 7 8 9 10 11 12 public class LightBulb { private int wattage; public int getWattage() { return wattage; } public void setWattage(int newWattage) { wattage = newWattage; } }
A variable declared inside of a block can not be accessed outside of that block.
True