In this video we are talking about final keyword:
— final keyword use with variable , methods and class
— if make a variable final then variable become constant
final int a=5;
//you cannot reassign a value to a
— final class
class A{
public void show(){
System.out.println(“In Calc show);
}
public void add(int a,int b){
System.out.println(a+b);
}
}
Suppose someone want to extend your class , but we want to stop inheritance then we need to make final
— if you make class final then no one can inherite your class
— but you can use the final class by making object of final class
class A{
public final void show(){
System.out.print(“IN A”);
}
}
class B extends A{
// but you inherit class but you cannot override show() method if your method is final
//since show method is final
}
— if you make method as final no one can override your method.