-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticKeyword.java
More file actions
40 lines (32 loc) · 1.02 KB
/
StaticKeyword.java
File metadata and controls
40 lines (32 loc) · 1.02 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
public class StaticKeyword {
// int num = 0; -> Not Valid for use in Static Method. non static without object
// creation it is not initialized
static int num = 10; // Valid Because Variable is Static. Varible is initialized without object
// creation.
public static boolean NegativeOrNot() {
if (num < 0) {
return true;
}
return false;
}
// =====================================
public static class DemoStatic {
DemoStatic() { // 3
System.out.println("Constructor: ");
}
static { // 1
System.out.println("Static Block: ");
}
{ // 1
System.out.println("Block: ");
}
public void sayHello(String name) {
System.out.println("Hello " + name + " Welcome ");
}
}
public static void main(String[] args) {
System.out.println(NegativeOrNot());
DemoStatic s = new DemoStatic();
s.sayHello("Shubham ");
}
}