User Tools

Site Tools


java:initializing_classes_and_constructors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java:initializing_classes_and_constructors [2020/09/16 17:51] mithatjava:initializing_classes_and_constructors [2020/09/16 18:15] (current) – [equals(other)] mithat
Line 153: Line 153:
 <code java> <code java>
 public boolean equals(ClickerCounter other) { public boolean equals(ClickerCounter other) {
-    return (this.count() == other.count() && this.maxCount == other.maxCount);+    return (this.count == other.count &&  
 +            this.maxCount == other.maxCount);
 } }
 </code> </code>
  
-It's up to you to decide what "equals" means. In many cases, "equals" means that two objects of the same class have the same state. So, in the above definition, for two counter to be equal, both the count and the maxCount must be the same. +It's up to you to decide what "equals" means. In many cases, "equals" means that two objects of the same class have the same state. So, in the above definition, for two counter to be equal, both the count and the maxCount must be the same. Now to use this method, assuming both of the variables below refer to valid ''ClickerCounters'': 
 + 
 +<code java> 
 +if (myCounter.equals(yourCounter) { 
 +    System.out.println("Our counters are the same."); 
 +} else { 
 +    System.out.println("Your counter and mine are not the same."); 
 +
 +</code>
  
 Copyright © 2020 Mithat Konar. All rights reserved. Copyright © 2020 Mithat Konar. All rights reserved.
java/initializing_classes_and_constructors.1600278701.txt.gz · Last modified: 2020/09/16 17:51 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki