Copy of a Constructor, By constructor and object

Java Programming Language / Class, Object and Methods in java

955

Program:

 class Studentcopy{
    int rollno;
    String name;

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

    Studentcopy(Studentcopy obj){
    rollno = obj.rollno;
    name =obj.name;
    }

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

    public static void main(String args[]){
    Studentcopy s1 = new Studentcopy(1,"Rahim");
    Studentcopy s2 = new Studentcopy(s1);
    s1.display();
    s2.display();
   }
}

Output:

1 Rahim
1 Rahim
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.