Series: Subject: Topic:
Question: 1268 of 2110

What is meant by static variable and static method

Asked by: Interview Candidate | Asked on: Sep 8th, 2005
Showing Answers 1 - 6 of 6 Answers

Answered On : Sep 8th, 2005

Both are class member n belong to defined class n object of class can;t access them  

Login to rate this answer.

Answered On : Sep 22nd, 2005

View all answers by yogeshpanda

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. 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.

Login to rate this answer.

Answered On : Oct 8th, 2005

         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.             

Login to rate this answer.

Answered On : Aug 31st, 2006

its wrongstatic variables can also be accessed in non-static methods

Yes  1 User has rated as useful.
Login to rate this answer.

Answered On : Mar 22nd, 2007

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.

Login to rate this answer.

Answered On : Jun 6th, 2007

Please Check with this example programpublic 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);}}

Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions



twitter fb Linkedin GPlus RSS


Interview Question

 Ask Interview Question?


Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.