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. public boolean equals(Person obj) {
  17. System.out.println("inside person equals");
  18. return false;
  19. }
  20. }
  21.  
  22. class Student extends Person {
  23.  
  24. public Student(String name, String x, int y, double d, int abc) {
  25. super(name, x, y, d, abc);
  26. }
  27.  
  28. public boolean equals(Student obj) {
  29. System.out.println("inside student equals");
  30. return true;
  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.1s 32688KB
stdin
Standard input is empty
stdout
inside student equals
true
inside person equals
false
inside person equals
false
inside person equals
false