November 17th, 2002, 09:47 PM
|
#1 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Pasadena, CA
Posts: 2,152
| Java Q - To extend a class or not
I have a class Person that has a toString() method in it. My main class creates a person object and stores each person object as part of a vector. I know vectors have a built in toString() but I want the the default toString() to be the one I have created in the Person class. Would it be better to have the Person class extend the Vector class? (public class Person extends Vector) or create another class Vector and just have the toString() that I want in there.
__________________
YAH! I knew you'd be jealous
|
| |
November 17th, 2002, 09:52 PM
|
#2 (permalink)
| | is 4 f00t secks
Join Date: Aug 2002 Location: Da Burgh
Posts: 4,509
|
i would just create another class vector. |
| |
November 18th, 2002, 01:33 AM
|
#3 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
|
why are you using a "vector"? http://java.sun.com/j2se/1.4.1/docs/...il/Vector.html Quote: |
My main class creates a person object
| define 'main' class, or post person class object class code, then 'main' class code. Quote: |
My main class creates a person object
| no, it doesn't. |
| |
November 18th, 2002, 02:34 AM
|
#4 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Pasadena, CA
Posts: 2,152
|
Last edited by Tekk : November 18th, 2002 at 02:37 AM.
|
| |
November 18th, 2002, 08:15 PM
|
#5 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 1,542
|
Er... your code doesn't seem to call vector.toString() anywhere. Why would you want to call vector.toString() anyway? |
| |
November 19th, 2002, 02:02 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Pasadena, CA
Posts: 2,152
|
Im a dummy  Hehe...I see now that since the vector holds the Person object, it will automatically use the Person.toString() and not the vector.toString(). |
| |
November 20th, 2002, 03:38 AM
|
#7 (permalink)
| | Senior Member
Join Date: Oct 2001
Posts: 881
|
qball.. i think you could be a bit nicer.
-Z |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |