CORRECT ACTUAL QUESTIONS AND
CORRECTLY WELL DEFINED ANSWERS
LATEST ALREADY GRADED A+ 2025 – 2026
b - ANSWERS-When testing a method's functional
correctness, what does it mean for a method to be correct?
*a.* it compiles and runs without errors
*b.* it does what it is supposed to do, and it doesn't do
what it is not supposed to do
*c.* it passes all the test cases
*d.* it does not have any performance issues
*e.* none of the above
c - ANSWERS-Which is true of JUnit testing when the unit
under test is a single method?
,*a.* JUnit testing can prove the correctness of the method
body
*b.* JUnit testing is generally considered an expensive
waste of time in industry
*c.* a single JUnit test case can show the presence of a
defect in the method body
*d.* a single JUnit test case can show the absence of defects
in the method body
*e.* none of the above are true
e - ANSWERS-Consider the following code:
private static int examScore(int studentNumber) { ... }
int k = examScore(42);
This code would certainly...
*a.* be illegal in Java (it's a compile-time error)
*b.* cause the program to crash when it is executed (it is a
run-time error)
*c.* print out the exam score of student #42
,*d.* assign an exam score of 42 to student k
*e.* be legal in Java (though flagged by Checkstyle)
c - ANSWERS-You may reason about the behavior of Java
code involving immutable types exactly as if they were
primitive types because:
*a.* "Immutable" and "primitive" are synonyms; there is no
difference between them
*b.* computations involving immutable types are just as
efficient as those involving primitive types
*c.* aliasing, which can happen with immutable types but
not primitive types, cannot cause trouble because object
values for immutable types cannot be changed
*d.* in any code where an immutable type is used in a way
where it would not behave like a primitive type, it causes a
Java compile-time error
c - ANSWERS-What are the values of str and num after the
call to foo?
private static void foo(String s, NaturalNumber n) {
s = "Columbus, " +s;
, n = new NaturalNumber2(43210);
}
String str = "Ohio";
NaturalNumber num = new NaturalNumber2(314);
foo(str, num);
*a.* str="Ohio", num=314
*b.* str="Columbus, Ohio", num=314
*c.* str="Ohio", num=43210
*d.* str="Columbus, Ohio", num=43210
d - ANSWERS-If x is an int variable, when does the boolean
expression evaluate to true?
((x % 5 != 0) && (x % 2 != 0))
*a.* when x is divisible by 5 or by 2 but not by both
*b.* when x is divisible by 10
*c.* when x is not divisible by 10
*d.* when x is neither divisible by 5 nor by 2
*e.* when x is either divisible by 5 or by 2