Functions toString and equals in class Object, and overriding them; dealing with equality of strings

Functions toString and equals in class Object, and overriding them; dealing with equality of strings

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Functions toString and equals in class Object Function toString in class Object Function toString in class Object is defined to return the name of the manilla folder, or object in which it appears. For example, evaluate this expression in DrJava’s interactions pane: new Object() and it will evaluate to something like [email protected] —that’s the name on the tab of the manilla folder or object, like the a0 or a1 that we have been writing from time to time. The name consists of the name of the class (including its package information), the @ sign, and then 6 hexadecimal digits, whose meaning you don’t have to know about at this point. Object’s function toString is inherited in every class but is usually overridden Since Object is the root of the class hierarchy, its function toString is inherited by every class, so the function appears in every object. However, if you define function toString in a class, your definition overrides the inherited one. So, the toString function that we wrote in class
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell.

Page1 / 2

Functions toString and equals in class Object, and overriding them; dealing with equality of strings

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online