I am new to java and still got a lot to learn. I have embedded C programming experience but totally new to object oriented programming.
I got the following that i need to understand. When you create a class in Java it is the blueprint of an object you are going to create. And say i have a GUI with a button that creates a new bicycle after i have clicked the create new bicycle button you enter all the instance variables that it asks for in your GUI etc.
Then when you finish with say clicking on a complete button a object is created. With all the data you supplied in your GUI to fit the blueprint.
So in your actionlistener when the complete button is pressed a piece of code like Bicycle bike = new Bicycle(); should run. But bike is static and you never know how many entries of bicycle's there is going to be. So how can the reference variable be made dynamic or act like its dynamic?
Sorry let me try and clear it up with the following.
public void actionPerformed(ActionEvent e) {
Bicycle bike = new Bicycle();
}
this is a action which is performed when Jbutton is pressed. This will create an object named "bike". But what happens when button is pressed again?Will it just override the previous object named bike?
And you dont know how many objects of bicycle type the user will create by pressing the button. So i was wondering if something like a array can be used in the following way
String bike[] = {"bike1","bike2,"bike3"};
for(int i=0;i<3;i++){
Bicycle bike[i] = new Bicycle();
}
or use a 'array list' because ultimately you wont know how many object will be created?
bikeis not static or anything like it, and the JVM does far more things dynamically than you might be used to.bikeobject is not static, it would be an instance variable - unless you mean it is "static" in the sense that it cannot take on another type of object. If you can explain more to this it might help. Last, if instead ofBicycle bike = new Bicycle()you used `Object bike = new Bicycle()', that would be more generic.ArrayList<E>. If you don't know what type you're going to create instances of, you can useObject- but you'll need to use reflection to create the instances themselves...