What Will Be The Output Of The Following Java Codep Pre #847
What will be the output of the following Java code?</p> <pre><code class="language-java"> import java.util.*; class A { LinkedList l = new LinkedList(); } class B extends A { void add(int a) { l.add(a); } } class C extends B { public void sum() { int sum=0; Iterator i = l.iterator(); while(i.hasNext()) sum+=(int)i.next(); System.out.println(sum); } } public class Sum { public static void main(String[] args) { C c = new C(); c.add(53); c.add(27); c.add(80); c.sum(); } }</code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Inheritance (Using Java) - Multilevel Inheritance - Quiz No.1.