package p2;
public class Test1 {
boolean temp;
int i;
/** Creates a new instance of Test1 */
public Test1(int i) {
System.out.println(i);
this.i = i;
}
public static void main(String args[]){
Test1 objTest1 = new Test1(5);
System.out.println(objTest1.i);
}
}
This Program Prints 5 and 5
But when I do small modification to the above program (by removing this key word)
package p2;
public class Test1 {
boolean temp;
int i;
/** Creates a new instance of Test1 */
public Test1(int i) {
System.out.println(i);
i = i; // Here I removed this Key Word
}
public static void main(String args[]){
Test1 objTest1 = new Test1(5);
System.out.println(objTest1.i);
}
}
I am getting output as 5 and 0.
Can you explain me why this is happening. I am expecting 5 and 5 in both cases.
Tahnks
public class Test1 {
boolean temp;
int i;
/** Creates a new instance of Test1 */
public Test1(int i) {
System.out.println(i);
this.i = i;
}
public static void main(String args[]){
Test1 objTest1 = new Test1(5);
System.out.println(objTest1.i);
}
}
This Program Prints 5 and 5
But when I do small modification to the above program (by removing this key word)
package p2;
public class Test1 {
boolean temp;
int i;
/** Creates a new instance of Test1 */
public Test1(int i) {
System.out.println(i);
i = i; // Here I removed this Key Word
}
public static void main(String args[]){
Test1 objTest1 = new Test1(5);
System.out.println(objTest1.i);
}
}
I am getting output as 5 and 0.
Can you explain me why this is happening. I am expecting 5 and 5 in both cases.
Tahnks