Hi All,
I've read some information for this but would like if you explain me why the output is different for this particular example.
package test03aug; public class MainClass { public static void main(String[] a) { Exam e=new Exam(); System.out.println(e.age); e.modifyVal(e.age); System.out.println(e.age); } } class Exam { int age; void modifyVal(int age){ age=age+1; System.out.println(age); } }
output:
0
1
0
package test03aug; public class MainClass { public static void main(String[] a) { Exam e=new Exam(); System.out.println(e.age); e.modifyVal(e.age); System.out.println(e.age); } } class Exam { int age; void modifyVal(int age){ this.age=age+1; System.out.println(age); } }
0
0
1