-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticDemo.java
More file actions
49 lines (36 loc) · 1.13 KB
/
StaticDemo.java
File metadata and controls
49 lines (36 loc) · 1.13 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
39
40
41
42
43
44
45
46
47
48
49
class Demo{
public int i;
public int j;
public static int k;
static{
System.out.println("Inside static block");
k = 51;
}
public Demo(){
System.out.println("Inside constructor");
this.i = 10;
this.j = 21;
}
public void fun(){
System.out.println("Inside fun method");
System.out.println("Value of i : "+this.i);
System.out.println("Value of j : "+this.j);
System.out.println("Value of K : "+Demo.k);
}
public static void gun(){
System.out.println("Inside gun method");
System.out.println("Value of k : "+Demo.k);
}
}
class StaticDemo{
public static void main(String A[]){
System.out.println("Inside main");
System.out.println("Value of k : "+Demo.k);
// Demo dobj = new Demo();
Demo.gun(); // Static can be accessed without using object
Demo dobj1 = new Demo();
Demo dobj2 = new Demo();
dobj1.fun(); // need object coz fun is non static method
dobj2.fun();
}
}