CSE 110 Exam 2 Quiz 7
The behavior of an object is defined by the object's
instance data
Use the following class definition: public class Swapper { private int x; private String y; public int z; public Swapper(int a, String b, int c) { x = a; y = b; z = c; } public String swap( ) { int temp = x; x = z; z = temp; return y; } public String toString( ) { if (x < z) return y; else return "" + x + z; } } If the instruction Swapper s = new Swapper(0, "hello", 0); is executed followed by s.toString( ); what value is returned from s.toString( )?
"00"
Use the following class definition: public class Swapper { private int x; private String y; public int z; public Swapper(int a, String b, int c) { x = a; y = b; z = c; } public String swap( ) { int temp = x; x = z; z = temp; return y; } public String toString( ) { if (x < z) return y; else return "" + x + z; } } If we have Swapper r = new Swapper (5, "no", 10); then r.swap( ); returns which of the following?
"no"
What is a mutator method?
A method that modifies a value
A constructor is a method that gets called whenever an object is created (instantiated) , for example with the new operator.
False
Assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye". The expression (s.concat(t).length( ) < y) is true.
False
Use the following class definition: public class Swapper { private int x; private String y; public int z; public Swapper(int a, String b, int c) { x = a; y = b; z = c; } public String swap( ) { int temp = x; x = z; z = temp; return y; } public String toString( ) { if (x < z) return y; else return "" + x + z; } } Which of the following criticisms is valid about the Swapper class?
The instance data z is visible outside of Swapper
A constructor must have the same name as its class.
True
Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?
foo(0 / 1, 2 * 3);
What is the return type of a method that does not returns any value?
void