Question

Explain use of final and super keywords in Java.

01 Dec 2023
Answer :
Word Count : 541

### 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;
________ ________ ________ ____ _________ _____ ___ ___.
_______ ___ ____ _________ ____ _______ __________.
_________ ___ ____ _________ _____ ____ ________ ____ ___ ____ __________.
______ ________ _______ ______ ________ _________ _______ ________ ____ ____ ____ ____.
___ _________ _________ _____ ___ __________.
___ ___ ______ ___ _____ _________.
_____ _______ _______ ___ __________.
____ ____ _________ ________ __________ _____ _________ _______ _______ ______ ________ ______.
____ ___ ____ ____ _______ __________.
______ ______ _________ _______ _____ ______ __________ _______ ________ ____ ______.
___ _____ _______ ______ ____ ________ ________ ________.
______ ____ _________ ___ ________ _________ ________.
_______ _______ ______ ________ ________ ______ ________ ____ __________ ______ ________ ___.
__________ ______ ______ ___ _____ ____ _______ _____.
______ _______ ___ ____ ________.
________ _________ _________ ___ _____ ________.
___ ________ ______ _____ _________ _____ ___ ________ ______ ________ __________.
________ ______ ___ ________ ____ __________ ___ ________ ___ _______ __________ _____.
______ ___ ________ __________ ___.
_____ ___ _____ ________ ____.
_____ ________ ______ ____ ______ _____ _________ _____ _______ ________ ____.
________ __________ ________ _______ ___ _____.
__________ ___ _________ ___ ____ _______ ___ _________ ______ _________ ____ ____.
_________ ________ ________ _____ _____ __________ _____ ________ _____ ________ _____.
__________ _____ ___ ________ ______ _________ ____ _________ _____ ___ ________.
____ ________ ___ __________ __________ ___ ________ ____.
_________ _______ _________ ___ _______ __________ ________ ________ __________ ____ _________ _____.
_________ ________ ________ __________ _________ _______ ___ _______ ______ _______ _____.
_______ __________ __________ ___ _______ __________.
____ ________ ______ ____ ______ _______ _________ ______.
_______ _______ _______ ____ _____ ________ _______.
_______ _________ ____ ________ ________ ____ _________ _______.
____ ____ ____ _____ __________.
_________ ____ _____ _________ ______ _________ ___ ______ ____ ____.
__________ __________ _______ _________ _______ ________ ___ _______.
_________ _____ ______ ________ ____ ____ ______ _____ __________ __________ _______ ____.
______ ______ _________ ______ ______ ___ ___ _____ _______ ___.
___ _______ __________ _____ _________ __________.
____ ________ __________ __________ ____ ___ ______.
______ ________ _____.

IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top