java:initializing_classes_and_constructors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
java:constructor_basics [2020/09/12 05:03] – [toString()] mithat | java:initializing_classes_and_constructors [2020/09/16 17:58] – [equals(other)] mithat | ||
---|---|---|---|
Line 145: | Line 145: | ||
Writing a '' | Writing a '' | ||
+ | |||
+ | |||
+ | ===== equals(other) ===== | ||
+ | |||
+ | Another method that you can define and is a good habit to get into defining is '' | ||
+ | |||
+ | <code java> | ||
+ | public boolean equals(ClickerCounter other) { | ||
+ | return (this.count() == other.getCount() && | ||
+ | this.maxCount == other.getMaxCount()); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | It's up to you to decide what " | ||
+ | |||
+ | <code java> | ||
+ | if (myCounter.equals(yourCounter) { | ||
+ | System.out.println(" | ||
+ | } else { | ||
+ | System.out.println(" | ||
+ | } | ||
+ | </ | ||
Copyright © 2020 Mithat Konar. All rights reserved. | Copyright © 2020 Mithat Konar. All rights reserved. |
java/initializing_classes_and_constructors.txt · Last modified: 2020/09/16 18:15 by mithat