1.

What Is The Difference Between A Class Variable And An Instance Variable In Java?

Answer»

Class VARIABLES only have a single copy of the variable and are declared with static modifiers. Every object of the class shares a single copy of the class variable, so if any changes are made to a class variable they will be seen by all the objects of a class. A class variable is allocated memory when the class is loaded first time.

EXAMPLE of a Class Variable Declaration in Java

Public class Product {

public static int Barcode;

}

Instance variables belong to an object and are specified without a static modifier. Every object of the class will have its own personal copy of the instance variable unlike class variables where single copy of the variable is shared by different objects of the class.

Example of an Instance Variable Declaration in Java

public class Product {

public int Barcode;

}

Big Data and HADOOP Certification Training

If you WOULD like more information about Big Data careers, please click the orange "Request Info" BUTTON on top of this page.

Class Variables only have a single copy of the variable and are declared with static modifiers. Every object of the class shares a single copy of the class variable, so if any changes are made to a class variable they will be seen by all the objects of a class. A class variable is allocated memory when the class is loaded first time.

Example of a Class Variable Declaration in Java

Public class Product {

public static int Barcode;

}

Instance variables belong to an object and are specified without a static modifier. Every object of the class will have its own personal copy of the instance variable unlike class variables where single copy of the variable is shared by different objects of the class.

Example of an Instance Variable Declaration in Java

public class Product {

public int Barcode;

}

Big Data and Hadoop Certification Training

If you would like more information about Big Data careers, please click the orange "Request Info" button on top of this page.



Discussion

No Comment Found