GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 745 of 937    Print  
what is the difference between static variables and static block? which gets executed first?

  
Total Answers and Comments: 3 Last Update: September 24, 2007     Asked by: jitender 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 24, 2007 09:12:58   
vmshenoy Member Since: October 2005   Contribution: 508    

RE: what is the difference between static variables an...
. When we declare a variable as static it means that all objects of that class share this single variable. such variables are global variables.static block or say function means we can access that function before any objects of its class are created and without reference to any object
 
Is this answer useful? Yes | No
February 09, 2007 02:58:02   
praveen kumar sakhamudi        

RE: what is the difference between static variables an...
static variable is also variable but every object share same memory locaction of static variable.

static block is block it have set of statements.

static block is execute first bec when ever.

class file is loded jvm static block is executed.



praveen kumar sakhamudi

(+91-9949735117)

 
Is this answer useful? Yes | No
September 24, 2007 04:16:05   
snehlata        

RE: what is the difference between static variables an...
Static variables belongs to class only and they will execute when they are displayed in System.out.println() statement. By default they have a fixed value.
e.g
for integer 0
for float 0.0
Static block is executed before main() because it has no need of object to execute this block. As we run program then it will automatically run.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape