Today in Programming Language, we will talk about some programming tools that are very important for beginners. So let us know what the variables are in the Programming Tools.
➧What is variable :
Variables represent a memory location that is used to store the data. This means that we can store our data in memory, through that variable. Before using the variable, it has to be cleared in its class and if you want, you can also assign a value to this variable.
For example, you might consider that if a student's name and his roll number are stored in a variable, then we will have to make a variable for that student's name in his class and make a different variable for his roll number and its value In that variable there will be asing.
There are types of variables in their class, while declaring them, they have to declare their type too, so that JVM (Java Virtual Machine) will be able to identify what type of value it is. If String is a value of type then you have to type the variable of String type and if you have the value of the Integer type then you have to call the variable of integer type. It Depends on you what type of variable you are taking.
➧Types of Variables :
There is a limit to store the values of variables that can not store that value more than that limit. This limites are called scope of variables, it is of 4 types based on its limite, which is the following -
- Local Variables.
- Instance Variables.
- Static Variables.
- Global Variables.
So let's know each of these variables one by one -
1. Local Variables :
Local variable is a variable that is declare within a function or method, it can only be used within that function or method, which is called Declare in a function or method. You can not use it in any other function or method because its scope is local.
It is only visible in the function or method in which it declares.
Source Code :
OUTPUT : Value of a : Java Tutorials
2. Instance Variable :
Instance variables are used inside the class and outside functions and methods. The instance variable is used like the global variable. The instance variable is also called Non-Static Variables.
Source Code :
OUTPUT : Value of a : Java Tutorials
3. Static Variables :
Static variables are also like instance variables, it is also written inside the class and outside functions and methods. Static variables are also called Class Class Variables. Static keywords are used to declare this. Which makes the variables static.
Static variables mean that it can not be changed after declaring variables.
Source Code :
OUTPUT : Value of a : 10
4. Global Variables :
Global variable is a variable that is declared outside the function. You can use this variable for every function, this variable is open source variable, you can use it easily in any of the functions you have created. .
This variable is publicly accessible.
Source Code :
OUTPUT : Value of a : Java Tutorials
So friends, I hope you have got a lot of information about the variables, even if you have any questions, you can ask me to comment and I will definitely answer the question you asked. Thanks!
Thank You !
So friends, I hope you have got a lot of information about the variables, even if you have any questions, you can ask me to comment and I will definitely answer the question you asked. Thanks!
Like this post, If you find Topic useful in this post, so share it with your friends and colleagues on Facebook, Twitter, whatsapp and Google Plus.
Thank You !
Note - Fore more Topics are available in www.kptechsolution.com.
0 Comments