+ 1
Why the method defined in this is not followed....and only the println variable is getting printed??
3 Answers
+ 14
@Satyam 
1)see method return type is void ... ie it doesn't return any value  
2) & even if it returns then also value returned is not stored in variable x ...
ie it is not written x=addOneTo (x);
+ 12
where is the code ?
+ 2
public class MyClass {
  public static void main(String[ ] args) {
    int x = 5;
    addOneTo(x);
    System.out.println(x);       
  }
  static void addOneTo(int num) {
    num = num + 1;
  }
}




