This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes please help me out  (about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please help me out  (about "composition")" Watch "please help me out  (about "composition")" New topic

please help me out (about "composition")

lang lang

Joined: Nov 01, 2003
Posts: 8

what "composition "mean?
thank you!!
[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ November 01, 2003: Message edited by: Jessica Sant ]
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Ok -- so I adjusted your code a bit (see my comments)

The WaterSource.toString() method is used to override Object.toString() method that every class inherits. This method is invoked whenever you try to print an objedct. So on the line I marked with **** the WaterSource.toString() method is invoked so that the contents of WaterSource is displayed however you choose.
When I run this code as you see it, I get the following output:
value1 = some Value
source = pipes

Try commenting out the WaterSource.toString() method, so that the default toString() is used, and you get this (the exact value you get for source will vary from execution to execution:
value1 = some Value
source = WaterSource@1a16869

Does that help?
[ November 01, 2003: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Consider Paul's rocket mass heater.
subject: please help me out (about "composition")
Similar Threads
A query on reusing the classes
this or super (call from sub class)
need help with calculation in my spreadsheet array
Guess what this prints...
doubt in method overloading..