Interface in Java with Examples
Interface in Java with Examples
Note :
• The variable does not necessarily have to be initialized at the time
of declaration. If it’s declared but not yet initialized, it’s called
a blank final variable. This approach is the most common.
• It is recommended to use uppercase to declare final variables in
Java.
void run ()
{
speedlimit = 400;
}
There is a final variable speed limit, we are going to change the value of
this variable, but it can’t be changed because the final variable once
assigned a value can never be changed.
In the case of a reference final variable, the internal state of the object
pointed by that reference variable can be changed.
Note that this is not re-assigning.
Bike10(){
speedlimit=70;
System.out.println(speedlimit);
}
In the above example, we have tried to override the final method in the
main() class. When we run the program, we will get a compilation error.
In the above example, we have created a final class named Final class.
Here, we have tried to inherit the final class from the Main class. When
we run the program, we will get a compilation error
Note:
• The final method can be inherited but you cannot override it.
• The blank Final Variable can be initialized only in the
constructor.
• Constructors cannot be declared as final because they cannot
be inherited.