srikanth mycherla wrote:
Iam unable to understand this line --Object reference variable is declared as an instance variable of a class ..
1)I have seen like object reference variable is always declared inside main method
please let me know such situations where object reference variable is declared as an instance member of a class or even in any normal method (not in a main method ) If possible please write small code ranchers ..
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
2)In 239 pg also i am unable to understand this line --what if the instance variable are objects?
and when the new object has instance variables that are object references rather than primitives ?
there is one example on this pg
public class cellphone {
private Antenna ant = new Antenna ();}
I suppose we usually create references inside main method ..correct me
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
In head first java of pg 238 and 239 i have a doubt ..
in pg 238 there is a statement ->" no matter where the object reference variable is declared (inside a method vs as as instance variable of a class ) the object always always always goes on the heap ..
Here i understood that the object always goes on heap even when object reference variable is declared inside a method ..(main method usually )
Iam unable to understand this line --Object reference variable is declared as an instance variable of a class ..
1)I have seen like object reference variable is always declared inside main method
please let me know such situations where object reference variable is declared as an instance member of a class or even in any normal method (not in a main method ) If possible please write small code ranchers ..
2)In 239 pg also i am unable to understand this line --what if the instance variable are objects?
and when the new object has instance variables that are object references rather than primitives ?
there is one example on this pg
public class cellphone {
private Antenna ant = new Antenna ();}
my opinion is this example should look like this i suppose
public class cellphone
{
public static void main(String args[])
{
private Antenna ant =new Antenna();}
3) IF the instance variable is a reference to an object both the reference and the object it refers are on the heap ...source from HFJ 247 BULLET POINT(2)
How come an instance variable be a reference to an object
I suppose we usually create references inside main method ..correct me
SCJP 6
Punit Singh wrote:
A very helpful post. Thank you. What you have written is all right, but I think, personally, I would prefer to instantiate the ant object in a constructor.And please use correct indentation, and start your class names with CapitalLetters, please.. . .
This is the right way.
It's just a flesh wound! Or a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|