Loading...
Loading...
Loading...
A new hostel student fills the form by copying a friend's and then changing the name, and sometimes the home address. Write Address (city, pin) and Student (name, Address) so that new Student(other) makes a deep copy. Print both students and whether they share one Address object.
SAME, or a new city and pin.<name> | <city> <pin> for the friend, then for the new student, then Same address object: <true or false>.Example
Input
Diya Chennai 600020 Meera Coimbatore 641001
Output
Diya | Chennai 600020 Meera | Coimbatore 641001 Same address object: false
With a shallow copy, Diya would "move" to Coimbatore too.
Try the problem first. Open one hint at a time.
Give Address its own copy constructor.
In Student(Student other), write this.address = new Address(other.address);, never this.address = other.address;.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor