Inheritance ยท May 5, 2026

๐Ÿงพ Java OOP Practical Exam โ€“ Set 14 (Advanced + Carefully Structured)

โฑ๏ธ Time: 2 Hours
๐Ÿ“Š Maximum Marks: 50


๐Ÿ“Œ Instructions (Read Carefully):

  • Attempt all questions.
  • Write each program in a separate class/file.
  • Follow proper OOP principles and structure.
  • Use Scanner class for input wherever required.
  • Output must be clearly labeled and formatted.
  • Add comments explaining important logic and decisions.

๐Ÿ”น Section A โ€“ Core Programming (30 Marks)


Q1. Class, Constructor & Multi-Condition Logic (10 Marks)

๐Ÿ“˜ Scenario: Movie Ticket Billing System

A cinema calculates ticket price based on show type and number of tickets.

๐Ÿ‘‰ Write a Java program with the following requirements:

  1. Create a class MovieTicket.
  2. Declare instance variables:
    • movieName (String)
    • showType (String) (โ€œMorningโ€ or โ€œEveningโ€)
    • numberOfTickets (int)
    • pricePerTicket (double)
  3. Create a parameterized constructor:
    • Initialize all variables using this
  4. Create a method calculateTotal():
    • Base total = numberOfTickets ร— pricePerTicket
    • If showType = “Evening” โ†’ add 20% extra charge
    • If numberOfTickets โ‰ฅ 5 โ†’ give 10% discount on final amount
  5. Create method displayDetails():
    • Display all details including final amount
  6. In the main() method:
    • Take input from user
    • Create object
    • Display result

Q2. Inheritance + Overriding + Combined Logic (10 Marks)

๐Ÿ“˜ Scenario: Courier Service Pricing

A courier company charges based on package type and weight.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create base class Courier:
    • Method calculateCost(double weight)
    • Default message: Cost calculation not available
  2. Create subclasses:
    • DocumentCourier
    • ParcelCourier
  3. Override method:
    • DocumentCourier:
      • โ‚น5 per kg
      • Minimum charge โ‚น50 (if calculated < 50, charge 50)
    • ParcelCourier:
      • โ‚น10 per kg
      • If weight > 10 kg โ†’ add โ‚น100 extra
  4. In the main() method:
    • Take weight as input
    • Create objects
    • Display calculated cost
  5. Output must show:
    • Courier type
    • Weight
    • Final cost

Q3. Encapsulation + Transaction Rules (10 Marks)

๐Ÿ“˜ Scenario: Digital Wallet with Limits

A wallet system enforces transaction limits and balance rules.

๐Ÿ‘‰ Write a Java program with the following requirements:

  1. Create class DigitalWallet.
  2. Declare private variables:
    • walletId (int)
    • userName (String)
    • balance (double)
  3. Provide getter and setter methods:
    • Balance must not be negative
  4. Create methods:
    • addFunds(double amount)
    • makePayment(double amount)
  5. Add conditions:
    • Maximum payment allowed per transaction = โ‚น5000
    • Balance must remain โ‰ฅ โ‚น200 after payment
    • Otherwise display: Transaction declined
  6. In the main() method:
    • Perform multiple operations
    • Display final balance

๐Ÿ”น Section B โ€“ Advanced OOP Concepts (20 Marks)


Q4. Abstract Class + Multi-Step Processing (10 Marks)

๐Ÿ“˜ Scenario: Billing System for Utilities

Different utilities calculate bills differently but share common display logic.

๐Ÿ‘‰ Write a Java program as follows:

  1. Create an abstract classUtilityBill:
    • Abstract method calculateBill(int usage)
    • Concrete method displayMessage() โ†’ prints "Bill Generated Successfully"
  2. Create subclasses:
    • WaterBill
    • InternetBill
  3. Implement method:
    • WaterBill:
      • โ‚น2 per unit
      • If usage > 100 โ†’ add โ‚น50 extra
    • InternetBill:
      • โ‚น500 fixed
      • If usage > 500 โ†’ add โ‚น100 extra
  4. In the main() method:
    • Take usage input
    • Call both methods
  5. Output must show:
    • Type of bill
    • Usage
    • Total amount

Q5. Runtime Polymorphism + Multiple Conditions (10 Marks)

๐Ÿ“˜ Scenario: Insurance Premium System

Different policies calculate premium differently.

๐Ÿ‘‰ Write a Java program:

  1. Create class Insurance:
    • Method calculatePremium(double amount)
    • Default: return 0
  2. Create subclasses:
    • HealthInsurance
    • VehicleInsurance
  3. Override method:
    • HealthInsurance:
      • Premium = 5% of amount
      • If amount > 5,00,000 โ†’ add โ‚น2000 extra
    • VehicleInsurance:
      • Premium = 3% of amount
      • Minimum premium โ‚น1000
  4. In the main() method:
    • Take amount as input
    • Use parent reference
    • Display premium
  5. Output must clearly show:
    • Insurance type
    • Amount
    • Premium

โญ Bonus Question (Optional โ€“ 5 Marks)

Q6. Exception Handling + Custom Logic

๐Ÿ“˜ Scenario: Login Attempt Limiter

๐Ÿ‘‰ Write a Java program to:

  1. Allow user to enter password
  2. Conditions:
    • Correct password = "admin123"
    • Maximum 3 attempts allowed
  3. If:
    • Wrong password โ†’ display "Incorrect password"
    • After 3 attempts โ†’ throw exception "Account Locked"
  4. Use:
    • Loop + try-catch
  5. Finally block should print: