forked from kaal-coder/hacktoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_46.java
More file actions
24 lines (21 loc) · 727 Bytes
/
Copy pathprogram_46.java
File metadata and controls
24 lines (21 loc) · 727 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
// instance block vs staic block
class o
{
int a=10; static int b=30;
o()
{
System.out.println("default constructor");
}
{ // instance block and it will run before constructor
System.out.println("yashpatel");
System.out.println(a+" "+b);// instance block will allow both static variable and non- static variable
}
static{ // for static block we need to use static keyword and it does not require any object
System.out.println("hii");
System.out.println(b);// static block will only allow the static variable it will not allow [a]
}
public static void main(String[] args)
{
o r=new o();
}
}