-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal4.java
More file actions
27 lines (27 loc) · 909 Bytes
/
Final4.java
File metadata and controls
27 lines (27 loc) · 909 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
class abc
{
abc(){num=30;}
//const to make constant in c
final float PI=3.14F; //read only variable
final int num;//blank final variable
void fxn()
{
// PI=50; //error we cannot change a constant value
//num=100; //you can't initialize here
final char ch;
ch='A';
System.out.println("the value of pi and num is "+PI+" "+num);
System.out.println("the value of pi and ch is "+PI+" "+ch);
}
}
class Main
{
public static void main(String[] args) {
abc obj=new abc();
obj.fxn();
}
}
//if you use final keyword before any variable then u cannot change it's value (i.e final makes variable constant)
//you cannot initialize a blank final variable in a function
//you can declare/initialize and use a blank final variable in any function locally
//you can initialize a blank final instance variable in a constructor