Explain use of final and super keywords in Java.
### The `final` Keyword:
In Java, the `final` keyword is used to restrict the functionality of a class, method, or variable. Once a class is declared as `final`, it cannot be subclassed, meaning no other class can extend it. When applied to a method, the `final` keyword indicates that the method cannot be overridden by subclasses. Finally, when used with a variable, it means the variable is a constant and cannot be reassigned after its initial assignment.
#### 1. Final Classes:
```java
final class Example {
// Class implementation
}
```
In this example, the class "Example" is declared as final, and no other class can extend it.
#### 2. Final Methods:
```java
class Parent {
final void display() {
// Method implementation
}
}
class Child extends Parent {
// This will result in a compilation error since you cannot override a final method.
}
```
Here, the `display` method in the `Parent` class is marked as final, preventing any subclass from overriding it.
#### 3. Final Variables:
```java
class Circle {
final double PI = 3.14;
________ ________ ________ ____ _________ _____ ___ ___.
_______ ___ ____ _________ ____ _______ __________.
_________ ___ ____ _________ _____ ____ ________ ____ ___ ____ __________.
______ ________ _______ ______ ________ _________ _______ ________ ____ ____ ____ ____.
___ _________ _________ _____ ___ __________.
___ ___ ______ ___ _____ _________.
_____ _______ _______ ___ __________.
____ ____ _________ ________ __________ _____ _________ _______ _______ ______ ________ ______.
____ ___ ____ ____ _______ __________.
______ ______ _________ _______ _____ ______ __________ _______ ________ ____ ______.
___ _____ _______ ______ ____ ________ ________ ________.
______ ____ _________ ___ ________ _________ ________.
_______ _______ ______ ________ ________ ______ ________ ____ __________ ______ ________ ___.
__________ ______ ______ ___ _____ ____ _______ _____.
______ _______ ___ ____ ________.
________ _________ _________ ___ _____ ________.
___ ________ ______ _____ _________ _____ ___ ________ ______ ________ __________.
________ ______ ___ ________ ____ __________ ___ ________ ___ _______ __________ _____.
______ ___ ________ __________ ___.
_____ ___ _____ ________ ____.
_____ ________ ______ ____ ______ _____ _________ _____ _______ ________ ____.
________ __________ ________ _______ ___ _____.
__________ ___ _________ ___ ____ _______ ___ _________ ______ _________ ____ ____.
_________ ________ ________ _____ _____ __________ _____ ________ _____ ________ _____.
__________ _____ ___ ________ ______ _________ ____ _________ _____ ___ ________.
____ ________ ___ __________ __________ ___ ________ ____.
_________ _______ _________ ___ _______ __________ ________ ________ __________ ____ _________ _____.
_________ ________ ________ __________ _________ _______ ___ _______ ______ _______ _____.
_______ __________ __________ ___ _______ __________.
____ ________ ______ ____ ______ _______ _________ ______.
_______ _______ _______ ____ _____ ________ _______.
_______ _________ ____ ________ ________ ____ _________ _______.
____ ____ ____ _____ __________.
_________ ____ _____ _________ ______ _________ ___ ______ ____ ____.
__________ __________ _______ _________ _______ ________ ___ _______.
_________ _____ ______ ________ ____ ____ ______ _____ __________ __________ _______ ____.
______ ______ _________ ______ ______ ___ ___ _____ _______ ___.
___ _______ __________ _____ _________ __________.
____ ________ __________ __________ ____ ___ ______.
______ ________ _____.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required