Given:
interface Event {
String getCategory();
}
public class CueSports {
public String getCategory() {
return “Cue sports”;
}
}
public class Snooker extends CueSports implements Event { // Line 9
public static void main(String[] args) {
Event obj1 = new Snooker(); // Line 11
CueSports obj2 = new Snooker(); // Line 12
System.out.print(obj1.GetCategory() + “, ” + obj2.getCategory());
}
}
What is the result?
A.
Cue sports, Cue sports
B.
Compilation fails at line 9
C.
Compilation fails at line 11
D.
Compilation fails at line 12
E.
Compilation fails at line 13
Explanation:
Class Snooker is public. Should be declared in a separate file.
B.Compilation fails at line 9
But the explanation should be:
The type Snooker must implement the inherited abstract method Event.getCategory()
If the class in different file, then the answer should be:
A
If they are in one file, then the error should occurs at
public class CueSports {
If the whole segment is in one java file, the line of compilation error shall be the first occurrence of public.
If not put in one java file, obj1.GetCategory() got compilation error, and shows no implementation.”The method GetCategory() is undefined for the type Event”
To correct my previous:
If the whole segment is in one java file, the line of compilation error shall be the first occurrence of public.
If not put in one java file, print as A
If the whole segment is in one java file, the line of compilation error will depends on the .java file name. The one (or both) public class which mismatch the file name will cause error.
To conclude:
If they were in two files, it should be A.
If the file name is “CueSports.java”, then the answer will be B.
If the file name is “Snooker.java”, then the compilation error will be at the line “public class CueSports {“.
A
the correct answer is B but if we change public class Snooker extends CueSports implements Event { // Line 9
to class Snooker extends CueSports implements Event { // Line 9
A will be the correct answer
Correct answer is E
GetCategory instead of getCategory
a