Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
if i declare a object inside a method then the reference variable become local whose life time is same as the method lifetime.what will happen to the object.can i say that once the method is finished the object is eligible for GC since the ref var scope is within the method only.



what about the final refrence variable inside a method.is the keyword final have any effect on my above conclusions...


finally only null, true, false are reserved word all the other are keyword.
comment on it.
 
Jagadesh cs
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


finally only null, true, false are reserved word all the other are keyword.
comment on it.


According to the JLS null, true and false are literals. they are not key words and the exam won't require you to find the difference between keywords and literals . its just enough if you know that they cant be used as identifiers, i.e. they are reserved words. ( This is present in K & B chapter 1 )



if i declare a object inside a method then the reference variable become local whose life time is same as the method lifetime.what will happen to the object.can i say that once the method is finished the object is eligible for GC since the ref var scope is within the method only.



Once a method has completed all objects local to it are eligible for GC ( of course unless a reference is returned by that method or some other refernce is given to that object )



what about the final refrence variable inside a method.is the keyword final have any effect on my above conclusions...



final identifier is just used to make sure that the value of a variable or its refernce cant be changed. It does not have any thing to do with the scope of a variable.


[ April 28, 2005: Message edited by: Jagadesh cs ]
 
Jane W pemberley
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think,
null,false,true are reserved words not keywords.
and all keywords are reserved.

Hope u can notice the difference
rgrds
Jane
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi jagadesh why i am doudting the final modifier is in the method local inner class the object can access only the final variable which means the variable is existing even the method finishes the execution. so i doubt that when giving final they may exists even outside the method scope.
 
soumya ravindranath
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Parameswaran,

it would be a good idea to give your posts a more descriptive title rather than "doubt" or "clear the doubt please" so that it will attract required attention.

My 2 cents,

Soumya.
 
Ariel Ortiz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parameswaran,

When a method ends its execution, all its local variables and parameters stop existing and the memory space that was allocated to them is disposed. So how can an instance of an inner class (method-local or anonymous) refer to local variables and parameters that are no longer available? What happens is that the instance of the inner class actually holds a copy of the values stored in these "external" variables and parameters used in the body of its method definitions. This explains why they must be declared final. If a variable is declared final, no one can change its value, so we can have a copy of the value of that variable in an other one and say they're both the same variable, although technically they're not. So you don't access the real variable inside a method of the inner class, all you get is a read-only copy of it, which happens to have the same name and (apparent) scope as the original final local variable or parameter of the method that holds the inner class.

I hope this clarifies your question.

...Ariel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic