Here is a self explanatory example:
package sample_java_package_1;
public class SampleClass_1 {
int i = 1;
public static void main(String[] args) {
SampleClass_1 obj1 = new SampleClass_1();
SampleClass_1 obj2 = new SampleClass_1();
SampleClass_1 obj3 = new SampleClass_1();
obj1.i = 5;
obj2.i = 6;
int a = obj1.i;
int b = obj2.i;
System.out.println(a);
System.out.println(b);
System.out.println(obj3.i);
}
}
package sample_java_package_1;
public class SampleClass_1 {
int i = 1;
public static void main(String[] args) {
SampleClass_1 obj1 = new SampleClass_1();
SampleClass_1 obj2 = new SampleClass_1();
SampleClass_1 obj3 = new SampleClass_1();
obj1.i = 5;
obj2.i = 6;
int a = obj1.i;
int b = obj2.i;
System.out.println(a);
System.out.println(b);
System.out.println(obj3.i);
}
}
No comments:
Post a Comment