-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalKeyword.java
More file actions
29 lines (27 loc) · 861 Bytes
/
Copy pathFinalKeyword.java
File metadata and controls
29 lines (27 loc) · 861 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
/*
* Final is the modifier applicable for classes, methods and variable.
* if a class is declared as final, it cannot be inherited.
* If a method is declared as final it cannot be override.
* If a variable is declared as final, it cannot be changed.
*/
final class FinalDemo{
public static void example(){
final int x=10;
// x=5; // gives error because final variables are unchangable
System.out.println(x);
}
final public static void finalMethod(){
System.out.println("hello");
}
}
/*class FinalDemoChild extends FinalDemo{ // cannot inherit final class
/*public static void finalMethod(){ // cannot override final method
System.out.println("HI");
}
}*/
class FinalKeyword{
public static void main(String[] args) {
FinalDemo.example();
FinalDemo.finalMethod();
}
}