-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticMethod.java
More file actions
28 lines (22 loc) · 814 Bytes
/
StaticMethod.java
File metadata and controls
28 lines (22 loc) · 814 Bytes
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
package Static_Keyword;
class Student{
int mark = 10;
static String teacher = "Kaveen";
static void display()
{
System.out.println("Hello Sir");
}
}
public class StaticMethod {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
s1.mark = 77;
s2.mark = 89;
Student.teacher = "Luke"; // The Teacher is update so update variable is print. Not old one. Becasue this staic
System.out.println(s1.teacher); // Luck print
Student.display();
System.out.println(s1.mark); // the Mark was updated for the mark --- S1 variable
System.out.println(s2.mark); // the Mark was updated for the mark --- S2 variable
}
}