What Will Be The Output Of The Following Java Codep Pre #636
What will be the output of the following Java code?</p> <pre><code class="language-java"> public class Sum { public static class Inner { static int sum=0; public static void add(int a, int b) { sum=a+b; } public void print() { System.out.println(sum); } } public static void main(String[] args) { Sum.Inner.add(10,20); Sum.Inner i = new Sum.Inner(); i.print(); } } </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 Types of Classes (Using Java) - Static Class - Quiz No.1.
What will be the output of the following Java code?
public class Sum { public static class Inner { static int sum=0; public static void add(int a, int b) { sum=a+b; } public void print() { System.out.println(sum); } } public static void main(String[] args) { Sum.Inner.add(10,20); Sum.Inner i = new Sum.Inner(); i.print(); } }
Runtime Error
Compilation Error
0
30