-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatic keyword
More file actions
44 lines (44 loc) · 877 Bytes
/
static keyword
File metadata and controls
44 lines (44 loc) · 877 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
package Sem4_JAVA;
//vanshika jain 2feb2022
//concept of static keyword
class A
{
static int i=1; //static variable
static int j=2;
int k=1431;
static void B() //static method
{
System.out.println("i:"+i);
}
void C() //non static method
{
System.out.println("non static method");
System.out.println("non static variable:"+k);
}
}
public class StaticDemo {
static int m=100;
static int n;
static void callme()
{
System.out.println("inside static method");
System.out.println("m:"+m);
}
static //static block
{
System.out.println("block1");
}
static
{
System.out.println("block2");
n=m+100;
}
public static void main(String[] args) {
A obj=new A();
callme();
System.out.println("n:"+StaticDemo.n);
A.B(); //calling static method
System.out.println("j:"+A.j); //printing static variable
obj.C(); //to call non static method
}
}