Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

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

POST Answer of Questions and ASK to Doubt

Previous Post Next Post