Instantiation and Constructor Summary
class MyClass {
public int x;
public int y;
MyClass() { // First Constructor
x = 0;
y = 0;
}
MyClass(int xx,int yy) { // Second Constructor
x = xx;
y = yy;
}
}
class MyProgram {
public static void main(String[] args) {
MyClass c1 = new MyClass();
c1.x = 3;
c1.y = 5;
c1 = new MyClass(3,5); // This line does the same as previous 3 lines
myClass c2 = new MyClass(10,12);
c2 = c1; // c2 references same memory as c1
// old c2 memory is lost
}
}