Given:
10. interface A { void x(); }
11. class B implements A { public void x() { } public
voidy() { } }
12. class C extends B { public void x() {} }
And:
20. java.util.List list = new java.util.ArrayList();
21. list.add(new B());
22. list.add(new C());
23. for (A a:list) {
24. a.x();
25. a.y();;
26. }
What is the result?
1 Compilation fails because of an error in
line 25.
2 The code runs with no output.
3 An exception is thrown at runtime.
4 Compilation fails because of an error in
line 20.
Answer Posted / pankaj malik
Compilation Error will be thrown at line 23 :
Type Mismatch: cannot convert from elemnt type Object to A.
| Is This Answer Correct ? | 9 Yes | 0 No |
Post New Answer View All Answers
What is the method in java?
What is r * in math?
What is the structure of java?
What is void class in java?
What is incompatible types in java?
What is java lang object?
Why set do not allow duplicates in java?
What is variable and example?
What does t in java mean?
What are the drawbacks of singleton class?
Can main() method in java can return any data?
What is the largest long allowed by java?
What types of index data structures can you have in java?
What is use of functional interface in java 8? Explain
What are the super most classes for all the streams?