Lecture9Object

Lecture9Object - Object: The Cosmic Superclass Most useful...

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

View Full Document Right Arrow Icon
Object: The Cosmic Superclass
Background image of page 1

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

View Full DocumentRight Arrow Icon
Most useful methods String toString ( ) boolean equals (Object otherObject) Object clone( )
Background image of page 2
toString ( ) Override the toString ( ) method to describe the object’s state e.g. For BankAccount: public String toString ( ) { return “BankAccount[balance = “ + balance + “]”; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Interesting Fact toString( ) is invoked whenever you concatenate an object with a String BankAccount michael = new BankAccount(1000); String info = “Information:”+ michael; String otherExample = michael;//won’t compile
Background image of page 4
Interesting Fact Can invoke superclass toString method: public String toString( ) { return super.toString( ) + “[ transactions: ” + transactioncount + “]”; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
Overriding equals( ) To override, the signature must be exact: public boolean equals ( Object other) { }
Background image of page 6
BankAccount equals public equals (Object other) { if (other == null) return false; if (getClass( ) != other.getClass( ) ) return false; //more }
Background image of page 7

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

View Full DocumentRight Arrow Icon
BankAccount equals public equals (Object other) { if (other == null) return false; if (getClass( ) != other.getClass( ) ) return false; //more }
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/13/2008 for the course CSC 216 taught by Professor Miller during the Spring '08 term at N.C. State.

Page1 / 15

Lecture9Object - Object: The Cosmic Superclass Most useful...

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

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