fork download
  1. class Person {
  2. private String name;
  3. protected String x;
  4. protected int y;
  5. protected double z;
  6. protected int abc;
  7.  
  8. public Person(String name, String x, int y, double d, int abc) {
  9. this.name = name;
  10. this.x = x;
  11. this.y = y;
  12. this.z = d;
  13. this.abc = abc;
  14. }
  15. }
  16.  
  17. class Student extends Person {
  18.  
  19. public Student(String name, String x, int y, double d, int abc) {
  20. super(name, x, y, d, abc);
  21. }
  22.  
  23. public boolean equals(Student obj) {
  24. System.out.println("inside student equals");
  25. return true;
  26. }
  27.  
  28. public boolean equals(Person obj) {
  29. System.out.println("inside person equals");
  30. return false;
  31. }
  32. }
  33.  
  34. public class Main {
  35. public static void main(String[] args) {
  36. Student s1 = new Student("John", "1", 10, 1.0, 10);
  37. Student s2 = new Student("John", "1", 10, 1.0, 10);
  38.  
  39. Person s3 = new Student("John", "1", 10, 1.0, 10);
  40. Person s4 = new Student("John", "1", 10, 1.0, 10);
  41.  
  42. System.out.println(s1.equals(s2)); // 1
  43. System.out.println(s1.equals(s3)); // 2
  44.  
  45. System.out.println(s3.equals(s4)); // 3
  46. System.out.println(s3.equals(s1)); // 4
  47. }
  48. }
Success #stdin #stdout 0.08s 32452KB
stdin
Standard input is empty
stdout
inside student equals
true
inside person equals
false
false
false