making a string .. name of an object
I want to input a string
Suppose the string was :
String s = "sani";
Now I want to make "sani" the name of an object of one of the class.
Suppose the name of the class is myClass.
I want to :
myClass sani = new myClass();
Any ideas??
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
Here I will create a class named StringClass and build constructors.....
public class StringClass
{
public static String StringAsObject;
// Defining the new Value of s when calling this method
StringClass()
{
StringAsObject = "sani";
}
// Building Constructors
public static String getStringAsObject()
{
return StringAsObject;
}
public void setStringAsObject(String s)
{
StringAsObject = s;
}
}
Now I will create a class named myClass that also contains method main and call the value of s which is the string "sani"
public class myClass
{
public static void main(String [] args)
{
StringClass aString = new StringClass();
String s;
s = aString.getStringAsObject();
StringClass.getStringAsObject();
System.out.println(s);
}
}
If this is not what you were referring to let me know because I am unclear.
Banderson
Junior Poster in Training
66 posts since Aug 2004
Reputation Points: 17
Solved Threads: 8
Thanks Branderson
StringClass aString = new StringClass();
this is what you wrote but I want it as
StringClass sani = new StringClass();
Is it possible like that .... whenever I input a string it should become the name of an object.
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
Okay fren ... but I'll keep on trying ...
nanosani
Unauthenticated Liar
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
hi everyone,
Is this what you mean?
String a = "sani";
Object k;
k = (Object)a;
//k has already been assigned the string "sani"
myClass k = new myClass( );
I hope this helps you
Yours Sincerely
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10