This is the special class of java which will never be inherited by any other class.

the final class contains all features of class only except inheritance.

the final keyword is required in-front of class, method, and variable if we want to provide final keyword then the variable value will be constant, the method can not be override and class can not be inherited.


final class Classname
{
     final datatype variable;
     datatype variable;
      returntype methodname()
      {

      }
     final returntype methodname()
     {

     }

}


NOTE:-  Final class can contain normal variable, normal method, constructor, static, properties and all functionalities of class only can not be inherited.



final class A
{

     final int x=12;
     int y;
     void fun()
     {
         System.out.println("fun");
     }
    final void fun2()
    {
       System.out.println("fun2");
    }
    public static void main(String args[])
    {
         A obj = new A();
        System.out.println(obj.x);
        obj.y=100;
        obj.fun();
        obj.fun2();
    }

}




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post