Copy of a Constructor, without Constructor by using object

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

1023

Program:

 class StudentCopy2{
    int rollno;
    String name;

    StudentCopy2(int i,String n){
    rollno = i;
    name = n;
    }

    StudentCopy2(){}

    void display(){
		System.out.println(rollno+" "+name);
		}

    public static void main(String args[]){
    StudentCopy2 obj1 = new StudentCopy2(1,"Rumman");
    StudentCopy2 obj2 = new StudentCopy2();

    obj2.rollno=obj1.rollno;
    obj2.name=obj1.name;

    obj1.display();
    obj2.display();
   }
}

Output:

1 Rumman
1 Rumman
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.