|
-
Feb 8th, 2012, 01:11 PM
#1
Thread Starter
Member
Instanciate an object with name inside a variable
Hello forumers !
My problem is the following.
I have a main class, Test, and another class called "Vehicle".
So, the normal instanciation to create the object is:
Vehicle car1 = new Vehicle(1, "Car1", 20); //for example...
What I wanna do is to read from keyboard a name, put it in a variable, and then, use that variable to replace car1. For example:
main{
String nameInstance = "";
nameInstance = "Ferrari";
Vehicle nameInstance = new Vehicle(...);
So, put the name of the variable, not the Ferrari in the isntanciation, but gives an error... Any way to do ??
Thanks !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|