You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69Lines changed: 69 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -273,6 +273,75 @@ Categories of Operators :
273
273
274
274
Note : The Code examples are given in the code file named as "operatr.java" above.
275
275
276
+
## Variables in JAVA
277
+
278
+
In Java, Variables are the data containers that save the data values during Java program execution. Every Variable in Java is assigned a data type that designates the type and quantity of value it can hold. A variable is a memory location name for the data.
279
+
280
+
### Categories of Variables :
281
+
282
+
Below we have different categories of variables with example explanation :-
283
+
284
+
- **Local** : A variable defined within a block or method or constructor is called a local variable.These variables are created when the block is entered, or the function is called and destroyed after exiting from the block or when the call returns from the function.
285
+
286
+
Syntax Code :
287
+
288
+
```
289
+
class Sample{
290
+
public statc void main(String[] a){
291
+
292
+
// defining a local variable here
293
+
int number = 12;
294
+
295
+
// Local to main method only
296
+
System.out.println("Local variable : " + number);
297
+
}
298
+
}
299
+
```
300
+
301
+
- **Instance** : Instance variables are non-static variables and are declared in a class outside of any method, constructor, or block.As instance variables are declared in a class, these variables are created when an object of the class is created and destroyed when the object is destroyed.
- **Static** : These variables are declared similarly to instance variables. The difference is that static variables are declared using the static keyword within a class outside of any method, constructor, or block.Static variables are created at the start of program execution and destroyed automatically when execution ends.
325
+
326
+
Syntax Code :
327
+
328
+
```
329
+
class Sample{
330
+
331
+
// Defining a static variable
332
+
public static int number = 34;
333
+
334
+
public static void main(String[] a)[
335
+
336
+
// Accessing the static variable here
337
+
System.out.println("Static variable declared inside the class : " + number);
338
+
339
+
]
340
+
}
341
+
```
342
+
343
+
Note : Further Explanation is been given in the code file above with name "var1.java".
0 commit comments