Returning false from Equals methods without Overriding

后端 未结 3 916
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 13:46

Write TestEquals class so that main method of Puzzle3 class prints false.

Note: You cannot override equals method o

3条回答
  •  误落风尘
    2021-01-29 14:00

    You may not override the equals method, but there is no reason you cannot overload the equals method.

    The method Object.equals has prototype:

    public boolean equals(Object o) { ... }
    

    To override this method you have to create a method with the same prototype in TestEquals. However your problem statement indicates that you are not allowed to override this method. No problem, overloading the method is a valid approach to accomplish your task. Simply add the following method definition to TestEquals:

    public boolean equals(TestEquals o) { return false; }
    

    And you're done.

提交回复
热议问题