-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21 Static Keyword.txt
More file actions
51 lines (41 loc) · 795 Bytes
/
21 Static Keyword.txt
File metadata and controls
51 lines (41 loc) · 795 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Emp
{
int eid;
int salary;
static String ceo;
public Emp() // when you create an object
{
eid = 1;
salary = 3000;
System.out.println("in constructor");
}
static // when you load a class
{
ceo = "Larry";
System.out.println("in static");
}
public void show()
{
System.out.println(eid + " : " + salary + " : " + ceo);
}
}
public class StaticDemo
{
static int i = 0;
public static void main(String[] args)
{
i = 9;
Emp navin = new Emp();
// navin.eid = 8;
// navin.salary = 4000;
// Emp.ceo = "Mahesh";
Emp rahul = new Emp();
// rahul.eid = 9;
// rahul.salary = 5000;
// Emp.ceo = "Mahesh"; // we dont need object
//
// Emp.ceo = "Nikita";
navin.show();
rahul.show();
}
}