Re: Problem with my Vectors

Rusty Haddock <[email protected]> Thu, 27 May 2004 00:08:20 -0500
Newsgroups gmane.comp.hardware.microcontrollers.tini
Organization 1/entropy
Message-ID <[email protected]>
Joel Rowley wrote:
    >Hey List,
    >??
    >I created a simple program that adds an instance of my
    >class to a vector.  Here is my program:
    >
    >-------------------------------------------------
<SNIP>
    >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?

Your declaration of the 'theName' element of TestClass.  static in Java
means something different than in 'C'.  If you don't remember (or haven't
learned yet :-) the static declaration modifier basically lets each
instantiation of TestClass share the 'theName' element.  Consequently,
each time you create a new TestClass object with an initializer, all
instances of the TestClass object "get" the new value for 'theName'.

This is not a TINI problem. :-)

	-Rusty-
-- 
   _____        Rusty Haddock  =  KD4WLZ  =  [email protected]
|\/   o \   o  **Out yonder in the Van Alstyne (TX) Metropolitan Area**
|   (  -<  O o              Microsoft is to software what
|/\__V__/                  McDonalds is to gourmet cooking
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini