Knowee
Questions
Features
Study Tools

Observe the below code :          public class InsurancePolicy   {              private int policyNumber;              private String holderName;              private double amount;                           public  double calculateBonusAmount(){                     //some logic                     return 0;              }                    }This class InsurancePolicy should not be inherited by any other classes. Drag and drop the apt choice to satisfy this condition.

Question

Observe the below code :          public class InsurancePolicy   {              private int policyNumber;              private String holderName;              private double amount;                           public  double calculateBonusAmount(){                     //some logic                     return 0;              }                    }This class InsurancePolicy should not be inherited by any other classes. Drag and drop the apt choice to satisfy this condition.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

To prevent a class from being inherited by any other classes in Java, you should declare it as a final class. So, the modified code would look like this:

public final class InsurancePolicy   
{              
    private int policyNumber;              
    private String holderName;              
    private double amount;                
              
    public double calculateBonusAmount(){   
        //some logic   
        return 0;   
    }                
} 

By adding the keyword 'final' before 'class', you are preventing any other classes from inheriting from InsurancePolicy.

This problem has been solved

Similar Questions

bserve the below code :       public class InsurancePolicy   {              private int policyNumber;              private String holderName;              private double amount;                             double calculateBonusAmount(){                     //some logic                     return 0;              }                    }             class VehicleInsurancePolicy extends InsurancePolicy       {              private String vehicleNumber;              private int noOfMonths;       }The calculateBonusAmount method in the parent class should not be overridden by any of its child classes.  Drag and drop the apt choice to satisfy this condition.

Observe the below code.  You have a class InsurancePolicy and another class VehicleInsurancePolicy that inherits InsurancePolicy.InsurancePolicy.javapublic class InsurancePolicy { private int policyNumber; private String holderName; private double amount; double calculateBonusAmount(){ //some logic return 0; } }VehicleInsurancePolicy.javaclass VehicleInsurancePolicy extends InsurancePolicy { private String vehicleNumber; private int noOfMonths;   double calculateBonusAmount(){ //some logic return 0; }}Which access specifier can be given to the overridden method calculateBonusAmount.

public abstract interface Insurance{public void insuranceDescription(String s);} Which is the correct class? Select one:a.public abstract class Car implements Insurance{ public abstract void insuranceDescription (String s) { }}b.public abstract class Car implements Insurance { }c.public class Car extends Insurance{public void insuranceDescription (Integer i) { }}d.public class Car implements Insurance{public void insuranceDescription (Integer i) { }}

public abstract interface Insurance{public void insuranceDescription(String s);} Which is the correct class? Select one:a.public abstract class Car implements Insurance{ public abstract void insuranceDescription (String s) { }}b.public class Car implements Insurance{public void insuranceDescription (Integer i) { }}c.public class Car extends Insurance{public void insuranceDescription (Integer i) { }}d.public abstract class Car implements Insurance { }

class Vehicle { protected int wheelsCount; private int doorsCount; public Vehicle(int wheelsCount, int doorsCount) { this.wheelsCount = wheelsCount; this.doorsCount = doorsCount; }}public class Truck extends Vehicle { private double loadCapacity; private int weight; public Truck(int wheelsCount, int doorsCount, double loadCapacity, int weight) { /* Missing Code */ }}

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.