| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Member
Join Date: Nov 2006
Posts: 56
Thanks: 13 Thanked 3 Times in 3 Posts Thanks: 13
Thanked 3 Times in 3 Posts
Rep Power: 3
|
final variables in method
Hi,
A method can have final and non-final variables in java. 1.Where these(final&non-final) variables are stored in JVM? 2.what is the life time of final variables of a method? 3.Can we access final variables of a method out side of that method, if so how? Give me example and detailed explanation. Wating for your answers.... |
|
|
|
|
|
#2 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: final variables in method
Hi shankar,
1A) In JVM Memory itself (in the HEAP) 2A) Method scope, if the method call or execution is finished then final variable is dead 3A) No you cannot, after all it is also a variable but which cannot be modified. we cannot access a local variable of a method from outside the method. please find the example given below publicclass FinalVariablesTest { publicfinalint FINAL_INT=100; publicvoid FinalVariableMethod() { finalint FINAL_INT1 =200; System.out.println("Final Variable in Method:"+FINAL_INT1); } publicstaticvoid main(String[] args) { FinalVariablesTest fvt = new FinalVariablesTest(); System.out.println("Final Variable of Class:"+fvt.FINAL_INT); fvt.FinalVariableMethod(); } } Please let me know your questions Thank You
__________________
M0h@n Last edited by t_mohan; 05-02-07 at 03:37 PM. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can we declare variables inside a method as Final Variables | preethisingh | Java Interview / Technical Questions | 1 | 02-02-07 11:54 AM |
| J2EE - What is final method? | preethisingh | Java Interview / Technical Questions | 1 | 23-01-07 08:29 PM |
| J2EE - Can you make a method final, without making the whole class final? | preethisingh | Java Interview / Technical Questions | 1 | 23-01-07 03:17 PM |
| java JSP | naga | JAVA Technologies | 4 | 21-08-06 05:03 PM |
| JAVA PART3 | naga | JAVA Technologies | 0 | 18-02-06 07:48 AM |