Delete core-java-modules/core-java-lang-oop-patterns/src/main/java/com/baeldung/shallowdeepcopy/Student.java

This commit is contained in:
Neetika23 2023-10-27 14:49:29 +05:30 committed by GitHub
parent 002def2d24
commit f20dbd4ed9
1 changed files with 0 additions and 27 deletions

View File

@ -1,27 +0,0 @@
package com.baeldung.shallowdeepcopy;
class Student {
private String name;
private int age;
private School school;
public Student(String name, int age, School school) {
this.name = name;
this.rollno = rollno;
this.school = school;
}
public Student(Student st) {
this(st.getName(), st.getAge(), st.getSchool());
} // standard getters and setters
}
@Override
public Object clone() {
Student student = null;
try {
student = (Student) super.clone();
} catch (CloneNotSupportedException e) {
student = new Student(this.getName(), this.getAge(), this.getSchool());
}
student.school= (School) this.school.clone();
return student;
}