-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaticDemo.java
67 lines (56 loc) · 1.75 KB
/
StaticDemo.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class StaticDemo
{
static
{
System.out.println("Inside static block of StaticDemo class which contains main");
}
public static void main(String arg[])
{
System.out.println("Inside main");
System.out.println("value of static no3:"+Demo.iNo3);
System.out.println("value of static no4:"+Demo.iNo4);
Demo.gun();
Demo obj1 = new Demo();
Demo obj2 = new Demo();
obj1.Fun();
}
public StaticDemo()
{
System.out.println("Inside constructor of StaticDemo");
}
}
class Demo
{
public int iNo1; //non static characteristics
public int iNo2; //non static characteristics
public static int iNo3; //static characteristics
public static int iNo4; //static characteristics
public Demo()
{
System.out.println("Inside Constructor");
iNo1 = 11;
iNo2 =21;
}
public void Fun()
{
System.out.println("Inside non static method Fun");
System.out.println("value of no1 :"+this.iNo1);
System.out.println("value of no2 :"+this.iNo2);
System.out.println("value of no3 :"+this.iNo3);
System.out.println("value of no4 :"+this.iNo4);
}
public static void gun()
{
System.out.println("Inside static method gun");
// System.out.println("value of no1 :"+iNo1);
// System.out.println("value of no2 :"+iNo2);
System.out.println("value of no3 :"+iNo3);
System.out.println("value of no4 :"+iNo4);
}
static
{
System.out.println("Inside static block ");
iNo3 = 51;
iNo4 = 101;
}
}