C212 WRITTEN TEST CERTIFICATION PREP
ACTUAL TEST WITH VERIFIED SOLUTIONS
100 PERCENT CORRECT
⩥ What is: mutual recursion?.
Answer: In a mutual recursion, a set of cooperating methods
calls each other repeatedly.
⩥ What is: backtracking?.
Answer: Backtracking is a problem solving technique that builds
up partial solutions that get increasingly closer to the goal. It
examines partial solutions, abandoning unsuitable ones and
returning to consider other candidates.
⩥ How many solutions are there altogether for the four queens
problem.
Answer: Two solutions.
⩥ How can you accidentally replicate instance variables from
the superclass?.
Answer: Since a subclass has no access to the private instance
variables of the superclass, when beginners get a compiler error,
,they commonly "solve" this issue by adding another instance
variable with the same name to the subclass. Sure, the
constructor now compiles, but it doesn't set the correct text! The
object now has two instance variables, both with the same name.
The constructor sets one of them, and the display method
displays the other. The correct solution is to access the instance
variable of the superclass through the public interface of the
superclass.
⩥ Where does the super/sub terminology come from?.
Answer: From set theory: subset and superset.
⩥ What is: accidental overloading?.
Answer: In Java, two methods can have the same name,
provided they differ in their parameter types. The Java compiler
considers them to be completely unrelated. We say that the
method name is overloaded. This is different from overriding,
where a subclass method provides an implementation of a
method whose parameter variables have the same types.
If you mean to override a method but use a parameter variable
with a different type, then you accidently introduce an
overloaded method.
, ⩥ Define: constructor chaining (automatic invocation of the
superclass constructor).
Answer: Unless specified otherwise, the subclass constructor
calls the superclass constructor with no arguments.
⩥ What is polymorphism?.
Answer: Polymorphism ("having multiple forms") allows us to
manipulate objects that share a set of tasks, even though the
tasks are executed in different ways.
⩥ Define: dynamic method lookup.
Answer: In Java, method calls are always determined by the
type of the actual object, not the type of variable containing the
object reference. This is called dynamic method lookup. It
allows us to treat objects of different classes in a uniform way.
⩥ Is the method call Math.sqrt(2) resolved through dynamic
method lookup?.
Answer: No. This is a static method of the Math class. There is
no implicit parameter object that could be used to dynamically
look up a method.
⩥ Define: abstract class(es).
ACTUAL TEST WITH VERIFIED SOLUTIONS
100 PERCENT CORRECT
⩥ What is: mutual recursion?.
Answer: In a mutual recursion, a set of cooperating methods
calls each other repeatedly.
⩥ What is: backtracking?.
Answer: Backtracking is a problem solving technique that builds
up partial solutions that get increasingly closer to the goal. It
examines partial solutions, abandoning unsuitable ones and
returning to consider other candidates.
⩥ How many solutions are there altogether for the four queens
problem.
Answer: Two solutions.
⩥ How can you accidentally replicate instance variables from
the superclass?.
Answer: Since a subclass has no access to the private instance
variables of the superclass, when beginners get a compiler error,
,they commonly "solve" this issue by adding another instance
variable with the same name to the subclass. Sure, the
constructor now compiles, but it doesn't set the correct text! The
object now has two instance variables, both with the same name.
The constructor sets one of them, and the display method
displays the other. The correct solution is to access the instance
variable of the superclass through the public interface of the
superclass.
⩥ Where does the super/sub terminology come from?.
Answer: From set theory: subset and superset.
⩥ What is: accidental overloading?.
Answer: In Java, two methods can have the same name,
provided they differ in their parameter types. The Java compiler
considers them to be completely unrelated. We say that the
method name is overloaded. This is different from overriding,
where a subclass method provides an implementation of a
method whose parameter variables have the same types.
If you mean to override a method but use a parameter variable
with a different type, then you accidently introduce an
overloaded method.
, ⩥ Define: constructor chaining (automatic invocation of the
superclass constructor).
Answer: Unless specified otherwise, the subclass constructor
calls the superclass constructor with no arguments.
⩥ What is polymorphism?.
Answer: Polymorphism ("having multiple forms") allows us to
manipulate objects that share a set of tasks, even though the
tasks are executed in different ways.
⩥ Define: dynamic method lookup.
Answer: In Java, method calls are always determined by the
type of the actual object, not the type of variable containing the
object reference. This is called dynamic method lookup. It
allows us to treat objects of different classes in a uniform way.
⩥ Is the method call Math.sqrt(2) resolved through dynamic
method lookup?.
Answer: No. This is a static method of the Math class. There is
no implicit parameter object that could be used to dynamically
look up a method.
⩥ Define: abstract class(es).