basic java programming question
help!
please concider the followwing code: Code:
Code:
i sort of get that these both "create" a new object(?, pointer?, instance?) of whatever you are trying to initialize(?). but (as you might have guessed) im still a little fuzzy on understanding it all completely. could anyone tell me A)what exaclty is this doing and B) what is the difference between what the first line does and the second line does. thanks for the help. |
The first line of the code declares the object in memory. The second line instantiates the object.
Think of it like a person - The first line declares the name of the person. The second line gives meaning to the person, i.e. brings it to life and gives it properties and sets what type of person this is. Hmm, I'm not very good at explaining this, try and look for some tutorials on Google, i'm sure they're better than me! |
Jestrik is right. In other (loose) terms, think of line 1 as defining/declaring a data structure ( eg C struct ) and line 2 as producing an 'instance' of that structure (with data) that you can actually use.
Chris PS Hi to Jestrik from another Hampshire-ite |
In Java, object values are effectively what are pointers in other languages. When you declare "Customer c;", it is initially set to NULL. Then when you do "new Customer()", it allocates memory and creates the object; then "c = ..." makes "c" point to this new object.
|
All times are GMT -5. The time now is 12:47 AM. |