Skip to content

Instantly share code, notes, and snippets.

@girish3
Created May 30, 2017 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girish3/b6d87efe83c5e082b1729a45bc443c1f to your computer and use it in GitHub Desktop.
Save girish3/b6d87efe83c5e082b1729a45bc443c1f to your computer and use it in GitHub Desktop.
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