Exception in thread “main” java.lang.Error: Unresolved compilation problem:
The final local variable daysInWeek cannot be assigned. It must be blank and not using a compound assignment

Final Method :

A final method is a method which cannot be overridden by a subclass. Lets create a superclass to understand the final method concept.

public class SuperClass {

public void myMethod()
{
System.out.println(“This is from myMethod in the SuperClass “);
}
public final void secondMethod()
{
System.out.println(“This is from Supercalss”);
}

}

And we can create a subclass by extrending the super class as below.

public class SubClass extends SuperClass{

public void myMethod()
{
System.out.println(“This is from myMethod in the SubClas “);
}// This will give you compilation error , as this method is defined as Final in the super class
public void secondMethod()
{
System.out.println(“This is from myMethod in the SubClas “);
}
}

Exception in thread “main” java.lang.VerifyError: class SubClass overrides final method .ÓÙ*h’+
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at Sample.TestOverriding.main(TestOverriding.java:5)

Final class :

A final class is a Java class which cannot be extended. This means that a final class can not become a superclass nor have a subclass.

An example final class is written below:
final class MySecureClass {
// This class cannot be extended
}

final class A {}

then that means that A cannot be further extended or subclassed.
This feature has a couple of big implications. One is that it allows control over a class, so that no one can subclass the class and possibly introduce

anomalous behavior. For example, java.lang.String is a final class. This means, for example, that I can’t subclass String and provide my own length() method

that does something very different from returning the string length.
There is also a big performance issue with final classes. If a class is final, then all of its methods are implicitly final as well, that is, the method is

guaranteed not be overridden in any subclass. A Java compiler may be able to inline a final method.