Skip to content

Commit

Permalink
Adding TypesOfVariables.java
Browse files Browse the repository at this point in the history
  • Loading branch information
iAdityaNarayanT committed Jun 4, 2022
1 parent e41876d commit 29cc22d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions Methods/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 8 additions & 18 deletions Methods/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Methods/src/aditya/TypesOfVariables.java
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

}
}

0 comments on commit 29cc22d

Please sign in to comment.