What Will Be The Output Of The Following Java Codep Pre #563
What will be the output of the following Java code?</p> <pre><code class="language-java"> import java.util.*; public class Main { LinkedList l = new LinkedList(); Main(int i) { l.add(i); } void add(int a) { l.add(a); } void sum() { int sum = 0; Iterator i = l.iterator(); while(i.hasNext()) sum+ = (int)i.next(); System.out.println(sum); } public static void main(String[] args) { Main a = new Main(35); Main b = a; a.add(45); b.add(32); b.add(64); a.add(23); a.sum(); b.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 Class Components (Using Java) - Assigning Objects - Quiz No.2.