aspose file tools*
The moose likes Java in General and the fly likes variable in place of object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "variable in place of object?" Watch "variable in place of object?" New topic
Author

variable in place of object?

Wayne Todd
Greenhorn

Joined: Oct 05, 2004
Posts: 2
I have a simple object called car:

public class Car{
int numMiles;
int year;

//default constructor
Car(){
System.out.println("Car created");
}

My question is this: If instantiate a number of cars (car1, car2, .., car100), is there any way for a user to nominate a particular car and modify its numMiles. This obviously won't work:

String myCar;
//user selects the car somehow but for here lets say
myCar="Car1";
myCar.numMiles=4000;
=====================================================
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I'm not sure I'm following, but it sounds like you might want to create an Array of Car objects. Then you could access a particular Car by its index number in the Array.



"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Wayne Todd
Greenhorn

Joined: Oct 05, 2004
Posts: 2
Perfect Marc, thank you for taking the time.
Wayne
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Or... :roll:

 
Consider Paul's rocket mass heater.
 
subject: variable in place of object?