donaricano-btn

 Final keyword

- It in java is used to restrict the user

- Stop Value Change

- Stop Method Overridding

- Stop Inheritance


1. How to use

- final keyword can be applied with the variables, a final variable that have no value it is called blank final variable or uninitialized final variable

- blank final variable

a. It can be initialized in the constructor only

b. It can be static also which will be initialized in the static block only


2. Final variable


Complile time error

Final variable once assigned a value can never be changed


3. Final method

 

Complile time error

- It cannot override it


4. Final class

 

Complile time error

- You cannot extend it


5. Question

1) Is final method inherited?

- final method is inherited but you cannot override

2) What is blank or uninitialized final variable?

- A final variable that is not initialized at the time of declaration is known as blank final variable

- It can be initialized only in constructor

 

3) static blank final variable

- A static final variable that is not initialized at the time of declaration is known as static blank final variable

- It can be initialized only in static block

 

4) What is final parameter?

- You cannot change the value of final it

 

Complile time error

5) Can we declare a constructor final?

- No, because is never inherited



'Back-End > Java_1' 카테고리의 다른 글

[Java] Static Binding and Dynamic Binding  (0) 2016.09.08
[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Instance initializer block  (0) 2016.09.07
[Java] Super keyword  (0) 2016.08.25
[Java] Covariant Return type  (0) 2016.08.24
블로그 이미지

리딩리드

,