GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 60 of 928    Print  
What is meant by static variable and static method

  
Total Answers and Comments: 6 Last Update: June 11, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
September 08, 2005 16:03:28   #1  
riteshyadav14@rediffmail.com        

RE: What is meant by static variable and static method
both are class member n belong to defined class n object of class can;t access them

 
Is this answer useful? Yes | No
September 22, 2005 04:35:32   #2  
yogeshpanda Member Since: September 2005   Contribution: 50    

RE: What is meant by static variable and static metho...
Static means no need of object.So either it is a static variable or static method no need to create an object of it.jst invoke by the class name.Static variable also posses the quality to have the scope of method in which it is declared& lifetime till prg. is executing.Static variable is initialised only 1 time in complete prg. execution.Ex.int count(){static int a 1;a+ 1;}If a prg is ruuning & calling count for 10 times then the count atlast will be 10 only not 2as static make it to initialise only for the 1st time & then the either the variable scope ended its value remains due to lifetime which equals the app. execution.static methods r methods that can be called onlt from static methods with class name.B'coz of this reason only main method is static as we dont need to make an obj. of class to invoke it from commandline.We do that from class name only & thats the reason we always name the main class the same with which we save it.
 
Is this answer useful? Yes | No
October 08, 2005 03:51:48   #3  
padma        

RE: What is meant by static variable and static metho...

Static means only one copy exists for the entire class irrespective of the number of objects tat exists for tat class.

Memory for the static members is created before the object is created becoz of this they can be called only with the class name.

Static variables can be accessed only in static methods.


 
Is this answer useful? Yes | No
August 31, 2006 03:12:41   #4  
chandra        

RE: What is meant by static variable and static metho...

its wrong

static variables can also be accessed in non-static methods


 
Is this answer useful? Yes | No
March 22, 2007 07:37:41   #5  
Madhivanan        

RE: What is meant by static variable and static metho...
In java static means common to class not specific to Objects.So static variables and static methods are accessible only by class name and not by objects.
 
Is this answer useful? Yes | No
June 06, 2007 04:50:04   #6  
Habeeb        

RE: What is meant by static variable and static metho...
Please Check with this example program

public class StaticExam {


static
int a 10;


public static void main(String args[])


{

System.out.println( Welcome to static variable testing );StaticExam s new StaticExam();


s.display();

}


public void display()


{

System.out.println( The value of static variable is +a);


}



}


 
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 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape