Do love programming? Do you love to programme using java? Though you may think that you are an expert but there are some things in java that can get you off guard.for example, do you know what are instance variables in Java? You might have learned about variable a lot but when it comes to instance variable it might appear to be different.here I will tell you what instance variables in Java are?
What are instance variables in Java?
To understand what are instance variables in Java? You first have to know about objects and what they do in java programming. When you know the objects than will agree with me that the so called instance variable is applied in java to store the object states
To give a clear definition of what are instance variables in Java? Will simply say that an instance variable is one that is defined without the inclusion Of static keyword and mostly is placed outside the method declaration .they are called instance variable because their value is instance-specific in nature and not at all shared in any way among other instances.
Rule for using instance variables
Using instance variables in java correctly you have to follow some rules.here is some of them
- Must be marked final
- Must be marked transient
- Can be used to mark abstract
- Cannot be used to mark synchronisation
- Cano not be applied to mark strict
- They cannot be identified as native
- They cannot be identified as static
- This instance variable in java can use any of the four access levels
Example
Just to give an example of what has been said, here is how to implement instance variables in java.
Public string page Name;
Here you could have created instance variable with public access
For the private access is done as below
Private Int page Number;
Final note
Today you have learned something new.keep in mind that with java programming you have to do a lot of practice so as to become an expert