1,

Part of the Throttle implementation from Chapter 2 is shown below. Match each method with the correct classification.
public class Throttle
{
public Throttle(int size)...
public double getFlow( )...
public boolean isOn( )...
public void shift(int amount)...
public void shutOff( )...
}
Answer

-A.B.C.
public Throttle(int size)...
-A.B.C.
public double getFlow( )...
-A.B.C.
public boolean isOn( )...
-A.B.C.
public void shift(int amount)...
-A.B.C.
public void shutOff( )...

2.
What is the common pattern of class definitions that is used in Chapter 2?
Answer
A.
Methods and instance variables are both private.
B.
Methods are private, and instance variables are public.
C.
Methods are public, and instance variables are private.
D.
Methods and instance variables are both public.
3.Here is part of the Throttle declaration

public class Throttle
{
public Throttle(int size) ...
public double getFlow() ...
public void shift(int amount) ...
}

Write several lines of Java code to create a Throttle called quiz with 100 positions, activate the method that shifts quiz's flow to the halfway
point, and then print the current flow from quiz.

Answer
A.
Accessor method
B.
Constructor
C.
Modification method
4,

Suppose that the Foo class does not have a clone method. What happens when an assignment x=y; is given for two Foo objects?
Answer

A.
x is set to refer to a copy of y's object
B.
x is set to refer to the same object that y refers to
C.
Compiler error
D.
Run-time error
5.
Suppose I create two Throttles using the class from Chapter 2:
Throttle mower = new Throttle(...);
Throttle copter = new Throttle(...);

Which statement best describes the instance variable called top for these two Throttles?
Answer
A.
mower.top and copter.top will always be two separate instance variables.
B.
mower.top and copter.top will only be separate if the two throttles are created with a different number of positions.
C.
mower.top and copter.top will never be two separate instance variables.
6.
Here is a small function that uses the Bag class from Chapter 3:

public static void quiz( )
{
int i; // Line 1
IntArrayBag b = new IntArrayBag( ); // Line 2
b.add(42); // Line 3
i = b.size( ); // Line 4
System.out.println(i); // Line 5
}
When is the Bag's array created?
Answer
A.
During the execution of Line 2.

B.
During the execution of Line 3.

C.
Just after Line 4 and before line 5.

D.
After Line 5.

Respuesta :

Answer:

Match the methods:

See attached file

---------------------------------------------------------------------------------------------------------------------------------------

2)

Methods are public, and instance variables are private in common pattern of a class definition program.

So, the correct option is (C).

- -----------------------------------------------------------------------------------------------------------------------------------------

3) Java code:

//Create a Throttle called quiz with 100 positions<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Throttle quiz = new Throttle(100);

//Method that shifts quiz's flow to the halfway

quiz.shift(50);

//Display the current flow from quiz.

System.out.println(quiz.getflow());

-------------------------------------------------------------------------------------------------------

4)

Assume that the Foo class does not have a clone method. Then x is set to refer to a copy of y's object for an assignment x=y; in two Foo objects

.

So, the correct option is (A)

-----------------------------------------------------------------------------------------------------------------------------------------

5)

The correct option is

A)

mower.top and copter.top will always be two separate instance variables.

Explanation:

Ver imagen chamberlainuket