|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ap.java.lang.Object
The class Object
as viewed from the perspective
of the Advanced Placement Computer Science Java subset.
See the complete Object
javadoc.
The root of the Java class hierarchy.
Constructor Summary | |
Object()
|
Method Summary | |
boolean |
equals(Object other)
Understanding how to implement equals is not part of the AP Java subset. |
int |
hashCode()
Understanding how to implement hashCode is not part of the AP Java subset. |
String |
toString()
According to the AP Java subset (A and AB) students are expected to understand that String concatenation using + invokes the toString() method on an object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Object()
Method Detail |
public boolean equals(Object other)
a.equals(b)
and a == b
(A and AB).
Determines if this object is "equal" to another object.
In general, objects should be instances of the same class
with the same guts to be considered equal. For example,
the code below only prints same value since
s
and t
are different strings though
they have the same value: "hello".
String s = new String("hello"); String t = new String("hello"); if (s.equals(t)) System.out.println("same value"); if (s == t) System.out.println("same string");
other
- is the other Object to which this one is compared
other
public String toString()
The toString() method is useful for printing an object and for returning a form of the object as a String in other contexts.
public int hashCode()
hashCode
is a method
of class Object (presumably for AB students only).
Note: when overriding equals
be sure
to override hashCode
as well or hard-to-find bugs
will occur if you put such an instance in a HashMap or HashSet.
|
unofficial documentation for the APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |