Multiple choice technology programming languages

class C{ static int s; public static void main(String a[]){ C obj=new C(); obj.m1(); System.out.println(s); } void m1(); { int x=1; m2(x); System.out.println(x+""); } void m2(int x){ x=x*2; s=x; }}

  1. prints 1,2

  2. prints 2,0

  3. prints 2,2

  4. compile time error

  5. Noneofthe above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In the main method, m1() is called. Inside m1(), x is a local variable with value 1. When m2(x) is called, Java passes x by value, so m2 receives a copy. In m2, this copy becomes 2 (x*2), but the original x in m1 remains 1. Static variable s is set to 2. Output: '1' from m1's println, then '2' from main's println of s.