arraylist - invoking method in main method in Java -
i have question regarding using method in main class, here code race class:
import java.util.arraylist; public class race { private arraylist<car>cars; public race(){ cars = new arraylist<car>(); } public void addcars(car car){ cars.add(car); } }
the above have done make arraylist cars ready put in using main method in class:
public class test { public static void main(string[] args) { car toyota = new car("toyota",1.0,1.0,2.0,2.0); cars.addcars(toyota); } }
however, has error in last line, shows "cars cannot resolved",i not sure how should fix it, maybe writing getter method in race class?
create instance of race
, call addcars
race race = new race(); race.addcars(toyota);
Comments
Post a Comment