Hi,
I'm a newbie, trying to learn OO via a Java course.
I'm on a section regarding expressions, operators / operands.
It states that if you use the == (equals to) operator with any of the opreands being a reference variable to instances of objects, it will always return false if they both do not contain the reference to the same object instance.
Is this just in java or true of any OO language when using object vars and the == (equals to) operator.
Also I was wondering if it is possible to create a primitave variable type which is equal to the value of the reference of the object instance (it's memory address).
Not sure I've explained that well, but it's like in perl, you can make a standard string scalar variable my $myvar = the memory reference of say a hash or array.
So it is a scalar variable not an object reference type variable.
Is this logic going to cause me problems and should I forget anything I know of other languages?
It's just it seems odd you need to create a variable of a class type if all it is going to do is hold a memory reference, not the actual object, which is all an object referecne is.
how big is an object reference variable if it isn't actually holding the object and its state attributes?
It just seems a bit alien to me to create two vars which are seamingly different (one being an object reference) and the other being a refrence to the object variable which is referencing the object instance...
my example..
why does myBook2 have to be a class defined reference variable, when it's just holding a memory location to the object referenced by myBook.
Any help undertanding why is appreciated.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
I'm a newbie, trying to learn OO via a Java course.
I'm on a section regarding expressions, operators / operands.
It states that if you use the == (equals to) operator with any of the opreands being a reference variable to instances of objects, it will always return false if they both do not contain the reference to the same object instance.
Is this just in java or true of any OO language when using object vars and the == (equals to) operator.
Also I was wondering if it is possible to create a primitave variable type which is equal to the value of the reference of the object instance (it's memory address).
Not sure I've explained that well, but it's like in perl, you can make a standard string scalar variable my $myvar = the memory reference of say a hash or array.
So it is a scalar variable not an object reference type variable.
Is this logic going to cause me problems and should I forget anything I know of other languages?
It's just it seems odd you need to create a variable of a class type if all it is going to do is hold a memory reference, not the actual object, which is all an object referecne is.
how big is an object reference variable if it isn't actually holding the object and its state attributes?
It just seems a bit alien to me to create two vars which are seamingly different (one being an object reference) and the other being a refrence to the object variable which is referencing the object instance...
my example..
Code:
Book myBook = new Book();
Book myBook2 = myBook;
why does myBook2 have to be a class defined reference variable, when it's just holding a memory location to the object referenced by myBook.
Any help undertanding why is appreciated.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!