Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A {
- private int a;
- public A(int a) { this.a = a; }
- @Override
- public final boolean equals(Object o) {
- // Check if the exact classes are the same
- if (this.getClass() != o.getClass()) return false;
- return this.a == ((A) o).a;
- }
- }
- class B extends A {
- private int b;
- public B(int a, int b) { super(a); this.b = b; }
- }
- A a = new A(0);
- B b = new B(0, 1);
- System.out.println(a.equals(b)); // false
- System.out.println(b.equals(a)); // false
- System.out.println(a.equals(a)); // true
- System.out.println(b.equals(b)); // true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement