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 are inner classes or non static nested classes in java?
What is the final access modifier in java?
Is main an identifier?
What are the types of methodology?
Can we have two main methods in a java class?
What is the difference between the ">>" and " >>>" operators in java?
What is composition in java?
Can we catch more than one exception in single catch block?
Is 0 a real number?
How do you remove an element from an arraylist in java?
Can we override protected method in java?
What is constructor chaining and how is it achieved in java?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. Define how can I do so?
How can I debug the Java security exceptions and AccessControlExceptions?
What are the types of strings?