What Will Be The Output Of The Following Java Codep Pre #562
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); } public static void main(String[] args) { Main a = new Main(20); Main b = a; b.l.add(40); System.out.println(a.l); System.out.println(b.l); } }</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.
What will be the output of the following Java code?
import java.util.*; public class Main { LinkedList l = new LinkedList(); Main(int i) { l.add(i); } public static void main(String[] args) { Main a = new Main(20); Main b = a; b.l.add(40); System.out.println(a.l); System.out.println(b.l); } }
[20, 40] [20, 40][20] [40][20] [20, 40]
Compilation Error