September 2018
Beginner
156 pages
3h 31m
English
First, we will create a new class. If we declare any variable as final, that means the value cannot be changed again. Let's consider the following code:
package coreJava;public class finaldemo { public static void main(String[] args) { //TODO Auto-generated method stub final int i=4; //constant variables }}
As you can see, we have declared the integer value as 4. This means we cannot change this value to another number. If we try to do that, it throws an error saying Remove 'final' modifier of 'i'. This keyword is useful if we want a value to be constant.
If we mark a class as final, it will throw an error because when we change the access mode to final, we are not able to use that as a parent class. In other words, we ...
Read now
Unlock full access