ALL ABOUT CLASS VARIABLES IN JAVA

 Important points to be noted

1. A class variable is a variable that is declared inside of class, but outside of any instance method or __init__ () method.

 2. It means it's a variable that is declared in the class        itself.

3.   Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. There would only be one copy of each class variable per class, regardless of how many objects are created from it.

4. If a class variable is a private variable, it is not accessible from outside of the class.


5.   Class variables are important because they are declared before any instance variables

6. Class variables are important because they are declared before any instance variables

7. Class variables have their own scope. They cannot be referred to by using the self variable when referring to an instance of a class.

8.Class variables exist in the current scope of the class, while global variables exist outside of the current scope of the class.

9. Class variables must always have a type. That is, they must be a class attribute that has a specific value.

10. Class variables must also be declared inside of the class. That is, they can not be declared elsewhere.

11.Class variables that are instance attributes are called instance variables.

12. Class attributes that are shared among multiple classes are called class variables.

13. Class variables are also called instance variables. The difference is a little subtle, but important.
 
14. Class variables must always be initialized. That is, they must be set to a value prior to their use.

15. Class variables can also be reassigned values.

16. Another important point is that a class variable can only be referenced within the class.

17. Class variables are accessed using the getattr () function. This function will return an object with a property called the class variable.

 I hope this has been helpful. 

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

It looks like you're using an ad blocker. We rely on ads to keep our site free, please whitelist us!

Click here to continue

Please whitelist our site to continue enjoying our content.

Whitelist | Close