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



Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy..

Answer / neil

Compilation fails because of an error in
line 25.

Is This Answer Correct ?    44 Yes 2 No

Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy..

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

Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy..

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

Post New Answer

More Core Java Interview Questions

What is the order of method invocation in an Applet?

1 Answers  


If I will write String s=new String("XYZ"); String s1=new String("XYZ"); if(s.equals(s1)){ sop("True"); } else{ sop("False"); } This program will give me "True". But When I am creating my own class suppose class Employee{ public Employee(String name); } Employee e= new Employee("XYZ"); Employee e1 = neew Employee("XYZ"); if(e.equals(e1)){ sop("True"); } else{ sop("False"); } Then it will give the output as "False". Can I know what is happening internally?

5 Answers  


What happens if we override private method?

0 Answers  


what is difference between Exception and Error?

36 Answers  


What is the synchronized method modifier?

0 Answers  


What is defined as false sharing in the context of multithreading?

0 Answers  


How to make a read-only class in java?

0 Answers  


Explain method local inner classes ?

0 Answers  


When is the finally clause of a try-catch-finally statement executed?

0 Answers  


Print Vertical traversal of a Binary Tree.

0 Answers   Amazon,


What is the set interface in java programming?

0 Answers  


What is lazy initialization in java?

0 Answers  


Categories