Multiple choice technology programming languages

Output of this program : class type { int num=12; void setnum(int num){ num=num; } int getnum() { return num; } public static void main(String[] args){ type obj=new type(); obj.setnum(10); System.out.print(obj.getnum()); } }

  1. 10

  2. 12

  3. compilation error

  4. none of these

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

In the setnum method, the parameter 'int num' shadows the instance variable 'int num'. When we write 'num = num' inside the method, we're assigning the parameter value to itself, not updating the instance variable. Therefore, the instance variable remains 12, which is what getnum() returns. The local scope takes precedence over the instance variable.