Given the two Java classes:
public class Word {
private Word(int length) {}
protected Word(String w) {}
}
public class Buzzword extends Word {
public Buzzword() {
// Line ***, add code here
}
public Buzzword(String s) {
super(s);
}
}
Which two code snippets, added independently at line ***, can make the Buzzword class compile?
A.
this ();
B.
this (100);
C.
this (“Buzzword”);
D.
super ();
E.
super (100);
F.
super (“Buzzword”);
this() constructor does not exists. It has to be this(“Buzzword”);
Answer C and F
+1
class Word {
private Word(int length) {
}
protected Word(String w) {
}
}
public class Buzzword extends Word {
public Buzzword() {
// Line ***, add code here
// super(“b”);
this(“b”);
}
public Buzzword(String s) {
super(s);
}
public static void main(String[] args) {
new Buzzword();
}
}
C F is correct.
C & F is correct option.
C and F
C F
C, F
C, F
// A. False. Recursive constructor invocation Buzzword()
// this ();
// B. False. The constructor Buzzword(int) is undefined
// this (100);
// C. True
// this (“Buzzword”);
// D. False. The constructor Word() is undefined
// super ();
// E. False. The constructor Word(int) is not visible
// super (100);
// F. True
// super (“Buzzword”);