GeekInterview.com
Series: Subject: Topic:
Question: 4 of 124

Java-Class variable Vs Instance variable

Some body please tell me what is the difference between class variable and instance variable???
Asked by: nitya123 | Member Since Sep-2012 | Asked on: Sep 9th, 2012

View all questions by nitya123

Showing Answers 1 - 4 of 4 Answers
cri

Answered On : Sep 9th, 2012

A class variable is a variable that is declared as static. This variable can be accessed even before the object of the class is created. i.e it would be available when the class is loaded. Where as instance variable is a variable that is declared at class level without the keyword static.

  
Login to rate this answer.
forjavajob

Answered On : Sep 28th, 2012

View all answers by forjavajob

A class variable which is declared as static is common to all the instances of the Class, i.e if you make any change in the class variable it applies to all the objects created for the class. In case of Instance variable- each object created for the class has its own instance variable copy.

  
Login to rate this answer.
arvindkore

Answered On : Oct 8th, 2012

class variable is static variable is create when class structure is defined ,and other variables which are create and destroyed with object are called instance variables

  
Login to rate this answer.
qamrun

Answered On : Nov 8th, 2012

View all answers by qamrun

Static variable, the field is allocated when the class is created. It belongs to the class and not any object of the class. It is class variable.

Instance variable, the field is allocated when the class is instantiated to the class is called instance variable or non-static variable

Static variable has only one copy for all the methods in class while instance variable has many copy.

Class can access only static variable while object can access both class and instance variable.

  
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

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Question Categories

Core Java Interview Questions

EJB Interview Questions

Hibernate Interview Questions

Java Interview Questions

Java Patterns Interview Questions

JDBC Interview Questions

JMS Interview Questions

JSP Interview Questions

Java OOPS Interview Questions

Ruby Interview Questions

Servlets Interview Questions

Spring Interview Questions

Struts Interview Questions

Websphere Interview Questions

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.