-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFinalKeyword.java
More file actions
39 lines (36 loc) · 1.02 KB
/
FinalKeyword.java
File metadata and controls
39 lines (36 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
package miscellaneous;
public class FinalKeyword {
public static void main(String[] args) {
FinalDemo fd = new FinalDemo();
System.out.println(fd.n);
System.out.println(fd.st);
// System.out.println(++fd.n); // value of the final variable cannot be changed.
System.out.println(fd.m);
System.out.println(FinalDemo.j);
FinalChild fc = new FinalChild();
fc.finalMethod();
}
}
class FinalDemo{
final int n = 5;
final int m;
final String st = "subhakanta";
FinalDemo(){
m = 9;
}
static final int j;
static{
j = 8;
}
final void finalMethod(){
System.out.println("method is declared final");
}
}
final class FinalChild extends FinalDemo{
// @Override
// void finalMethod(){ // the final methods cannot be overridden.
// System.out.println("final method overriding :)");
// }
}
// class FinalSuperChild extends FinalChild{ //the final class cannot be inherited(extended)
// }