Sunday 17 March 2013

SCJP - 16 - Using the fragments below, complete the following code so it compiles. Note, you may not have to fill all of the slots.


Answer:


As there is no droppable tile for the variable x and the parentheses (in the Kinder constructor),
are already in place and empty, there is no way to construct a call to the superclass constructor
that takes an argument. Therefore, the only remaining possibility is to create a call to the no-argument
superclass constructor. This is done as: super();. The line cannot be left blank, as the
parentheses are already in place. Further, since the superclass constructor called is the no-argument
version, this constructor must be created. It will not be created by the compiler because
there is another constructor already present.
(Objective 5.4)
==
class AgedP {
__________ __________ __________ __________ __________
public AgedP(int x) {
__________ __________ __________ __________ __________
}
}
public class Kinder extends AgedP {
__________ __________ __________ _________ ________ __________

public Kinder(int x) {
__________ __________ __________ __________ __________ ();
}
}
Fragments: Use the following fragments zero or more times:
AgedP super this
( ) { }
;
===
class AgedP {
AgedP() {}
public AgedP(int x) {
}
}
public class Kinder extends AgedP {
public Kinder(int x) {
super();
}
} 


No comments:

Post a Comment