SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
pagano monello wrote:In effect, in this way, we don't instantiate the variable, which would be completely wrong.
pagano monello wrote:However I think that, in this way, we define a reference variable which points to a null value (default value for reference variables)
pagano monello wrote:What I may conclude is just the following rule (which is just a rule I deduce from the context, but which is not so clear to me): it's not allowed to instantiate interface variables, but it is correct to define interface variables, which point to null.
Ankit Garg wrote:There is another way to create instance of Movable, through anonymous inner class:
Roel De Nijs wrote:1/ (anonymous) inner classes are not on the OCA exam so don't worry if you don't understand anything of this code (that's why I decided not to add such a code example, because the syntax looks weird and complex). Inner classes is a topic on the OCP exam.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
However I think that, in this way, we define a reference variable which points to a null value (default value for reference variables)
Now when you instantiate the Fun class, reference variable m will be assigned a null value, because that's the default value for instance and class reference variables.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
pagano monello wrote:I the first instance variable (f1) doesn't point to any object, because I have not instantiated class Fun by using the new operator (new Fun();).
On the other hand the instance variable points to a null object. Am I right, I am not?
pagano monello wrote:
Now when you instantiate the Fun class, reference variable m will be assigned a null value, because that's the default value for instance and class reference variables.
I do not understand in which way I am instantiating class Fun. I think I am not instantiating class Fun in this snippet.
pagano monello wrote:
if I use a reference variable (mov) in a class, this variable is initialized to null when an object is created (now mov is an attribute of an object of class Fun). In this case the reference variable is an instance variable.
pagano monello wrote:
on the other hand, if I use a reference variable (mov) as a method parameter, it's just a reference variable, and not an instance variable, so in this case of course it isn't attribute of an object, therefore it doesn't need to be instantiated to any value.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|