hi i want to understand the flow of execution of this program.i am new to programming and learning constructors in java.
My doubt is when object obj calls the constructor and assigns the value 10 and jack to x and y, then isn't it that when the next object obj2 is created it will replace the value with 12 and matt in x and y ? so since the call() method is called after that isn't it suppose to print 12 and matt to both the calls as the print is printing x and y ?
class Constructor2 {
int x;
String y;
Constructor2(int i, String s){
x = i;
y = s;
}
void call(){
System.out.println("roll no is "+ x + " name is " + y);
}
public static void main(String args[]) {
Constructor2 obj = new Constructor2(10, " jack ");
Constructor2 obj2 = new Constructor2(12, " matt ");
obj.call();
obj2.call();
}
}