Re: Problem with my Vectors

Barry Demchak <[email protected]> Wed, 26 May 2004 20:16:45 -0700
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <[email protected]>
For "private static String theName;", try getting rid of "static".

At 07:14 PM 5/26/2004, Joel Rowley wrote:
>Hey List,
>Â
>I created a simple program that adds an instance of my
>class to a vector.  Here is my program:
>
>-------------------------------------------------
>import java.util.*;
>
>import com.dalsemi.system.Debug;
>
>public class VectorTest {
>
>         public static void main(String[] args) {
>                 Debug.setDefaultStreams();
>                 Vector vecTest = new Vector(8, 2);
>                 vecTest.addElement(new TestClass("theName"));
>
>System.out.println(((TestClass)vecTest.elementAt(0)).getTheName());
>                 vecTest.addElement(new TestClass("theName1"));
>
>System.out.println(((TestClass)vecTest.elementAt(0)).getTheName());
>
>System.out.println(((TestClass)vecTest.elementAt(1)).getTheName());
>         }
>}
>-----------------------------------------------
>
>Here is what my TestClass looks like:
>
>-----------------------------------------------
>public class TestClass {
>
>         private static String theName;
>
>         TestClass(String name) {
>                 theName = name;
>         }
>
>         public String getTheName() {
>                 return theName;
>         }
>
>}
>-----------------------------------------------
>
> >From what it looks like, the program should output
>this:
>
>theName
>theName
>theName1
>
>But, what it outputs this:
>
>theName
>theName1
>theName1
>
>What is my problem?
>
>Thanks!
>Joel Rowley
>_______________________________________________
>TINI mailing list
>TINI-6tN4nzCoH/[email protected]
>To UNSUBSCRIBE, edit your profile, or see list archives:
>http://lists.dalsemi.com/mailman/listinfo/tini


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
: Barry Demchak               :
: Torrey Pines Software, Inc. :
: http://www.tpsoft.com/      :
: (858) 452-8700              :
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini