-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e41876d
commit 29cc22d
Showing
3 changed files
with
30 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package aditya; | ||
|
||
public class TypesOfVariables { | ||
static int a=10; // static variable | ||
static int b=20; // static variable | ||
int c=30; // instance variable | ||
public static void main(String[] args) { | ||
int d = 40; | ||
/* | ||
Static variable can be accessed in two ways inside a method: | ||
1.directly accessed | ||
2. accessed via class name | ||
*/ | ||
System.out.println(a); // METHOD 1 of accessing static variables | ||
System.out.println(TypesOfVariables.b); //METHOD 2 of accessing static variable using class name | ||
TypesOfVariables object = new TypesOfVariables(); // making object of class which has the instance variable in order to access the instance variable | ||
System.out.println(object.c); // accessed instance variable using object and dot operator | ||
System.out.println(d); // local variable directly accessed | ||
|
||
} | ||
} |