logo

APSU Notes


Quiz 7

Question 1

Which of the following best describes the relationship between classes and objects?

An object is an instance of a class.

Question 2

All methods must return a value.

False

Question 3

A variable that is declared inside of a method is called ______ variable.

local or instance

Question 4

What does the keyword this refer to?

The object the current method is being called on.

Question 5

A variable declared in one method can have the same name as variable declared in another method.

True

Question 6

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.

Question 7

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!");
    }
}

Question 8

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();

Question 9

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.

Question 10

Method definitions can be marked as private?

True

Question 11

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;
    }
}

Question 12

A variable declared inside of a block can not be accessed outside of that block.

True