-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariables.java
More file actions
38 lines (30 loc) · 1.08 KB
/
Variables.java
File metadata and controls
38 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// -- Variables -- //
class Variables {
// Static Variable
// Shared among all instances of the class
static String collegeName = "ABC College";
// Instance Variables
// Non-static variables that belong to each instance of the class
int id;
String name;
Variables(int sId, String sName) {
id = sId;
name = sName;
}
void display() {
// Local Variable
// Declared inside a method and can only be used within that method
int passingScore = 40;
System.out.println("College: " + collegeName); // Accessing Static Variable
System.out.println("ID: " + id + " | Name: " + name); // Accessing Instance Variables
System.out.println("Passing Score: " + passingScore); // Accessing Local Variable
}
public static void main(String[] args) {
// Creating an instance of Variables class
Variables s1 = new Variables(101, "Riya");
s1.display();
// Changing Static Variable
Variables.collegeName = "XYZ University";
s1.display();
}
}