Reputation: 1
I need to create an array of objects (Cars) and then initialise the array to be of a required size (10) within a constructor. So far I have this:
public class Queue {
private Car [] car;
public Queue (Car [] car) {
Car [] car = new Car[10];
}
}
Which when I compile says it cannot find the Car symbol. I'm presuming the problem is with the creation of the array as I don't seem to have created the Car properly. Any help would be appreciated <3
Upvotes: 0
Views: 15670
Reputation: 7940
Create a Car Class and put it in classpath and it will work smoothly .
EDIT[2nd time]: editing my code as per commments below. This shld work
public class Queue {
private Car [] mycar;
public Queue (Car [] car) {
mycar = car;
}
}
EDIT:
class Car {
}
Upvotes: 0
Reputation: 751
This is the proper way to create it.
public class Queue {
private Car [] car;
public Queue () {
car = new Car [10];
}
}
Provided that you have defined the car class.
Upvotes: 2