Short Answers Section 2.1 - 2.2 Introduction to Classes |
public class Throttle { public Throttle(int size) ... public double getFlow() ... public void shift(int amount) ... }
Throttle x;
Throttle y;
x = new Throttle(100);
x.shift(25);
y = x;
y.shift(25);
System.out.println(x.getFlow( ));
System.out.println(y.getFlow( ));
Short Answers
Section 2.3
Packages
Short Answers
Section 2.4
Parameters, Equals, Clones
public static foo(Location spot)
{
spot.shift(2,0);
}
Now, suppose that s is a reference to a Location with s.getX( ) equal to
40. Then the method foo(s) is activated. What is the value of s.getX( )
after this activation?
public static foo(int spot)
{
spot += 2;
}
Now, suppose that s is an integer with a value of
40. Then the method foo(s) is activated. What is the value of s
after this activation?
Location a, b, c;
a = new Location(10,20);
b = new Location(10,20);
c = b;
...
After this code executes, what are the values of these boolean expressions?
a==b
a.equals(b)
a==c
a.equals(c)
b==c
b.equals(c)
Also, write two clear sentences telling me the difference between == and the
equals method for the Location class.
Location a, b, c;
a = new Location(10,20);
b = (Location) a.clone( );
b.shift(3,0);
...
After this code executes, what are the x-coordinates of a and b?
Also, write two clear sentences telling me the difference between = and the
clone method for the Location class.
Multiple Choice Section 2.1 - 2.2 Introduction to Classes |
Throttle mower = new Throttle(...); Throttle copter = new Throttle(...);
Multiple Choice
Section 2.3
Packages
Multiple Choice
Section 2.4
Parameters, Equals, Clones