Download 1-chapter1-1_objects-and-methods

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Horner's method wikipedia , lookup

Newton's method wikipedia , lookup

Root-finding algorithm wikipedia , lookup

False position method wikipedia , lookup

Transcript
Objects and methods
CSC 113: Computer programming II
1
2
3
4
5
6
7
8
The Method toString
•
•
•
•
public value-returning method
Takes no parameters
Returns address of a String object
Output using print, println, printf
methods
• Default definition creates String with name
of object’s class name followed by hash code
of object
9
The Method toString
• Implementing toString method in java is done
by overriding the Object’s toString method.
• The java toString() method is used when we
need a string representation of an object.
• It is defined in Object class.
• This method can be overridden to customize
the String representation of the Object.
10
Object toString() method :
PointCoordinates@119c082
PointCoordinates@119c082 testing
11
When you run the ToStringDemo2
program, the output is:
X=10 Y=10
X=10 Y=10 testing
12
13
14
15
36)
16
36)
17
18
19
20
21
22