Created
May 30, 2017 15:46
-
-
Save girish3/b6d87efe83c5e082b1729a45bc443c1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Human { | |
public String name; | |
public Human(String name) { | |
this.name = name; | |
} | |
} | |
public class Student { | |
private Human human; | |
private int id; | |
public Student(Human human, int id) { | |
this.human = human; | |
this.id = id; | |
} | |
} | |
public static void main(String[] args) { | |
Human h = new Human("foo"); | |
Student s = new Student(h, 1); | |
// changing the Human object which is supposed to be private. | |
h.name = "bar"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment