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.
Answers were Sorted based on User's Feedback
Answer / neil
Compilation fails because of an error in
line 25.
| Is This Answer Correct ? | 44 Yes | 2 No |
Answer / 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 |
Answer / r.jainrocks@gmail.com
Compilation fails because of an error in
line 25.
because interface A has no method definition for method y()
....
| Is This Answer Correct ? | 9 Yes | 4 No |
what is server side caching?
What's the base class in java from which all classes are derived?
Does a function need a return?
I want to persist data of objects for later use. What’s the best approach to do so?
What is the difference between JDK and JVM?
Can we write a class without main method in java?
Define a package.
What causes memory leak in java?
What is the file extension for java?
Matrix multiplication only using OOP concepts .
Add a value x to array from index l to r where 0 <= l <= r <= n-1
what is real-time example of runtime polymorphism and compile time polymorphism