๐Ÿงพ Java OOP Practical Exam โ€“ Set 3 (New)

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

Instructions:

  • Attempt all questions.
  • Write clean, properly indented Java code.
  • Use meaningful variable and method names.
  • Add comments wherever required.
  • Follow proper OOP principles.

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


Q1. Class, Object & Constructor (10 Marks)

A mobile shop wants to manage smartphone details.

๐Ÿ‘‰ Write a Java program to:

  1. Create a class Mobile with the following data members:
    • brand (String)
    • model (String)
    • price (double)
  2. Create a parameterized constructor to initialize all values.
  3. Create a method displayMobile() to print mobile details.
  4. In the main() method:
    • Create at least 3 mobile objects
    • Display details of all mobiles

Q2. Inheritance & Method Overriding (10 Marks)

A food delivery system calculates delivery charges differently.

๐Ÿ‘‰ Write a Java program to:

  1. Create a base class Delivery with:
    • Method calculateCharge() (default implementation)
  2. Create two derived classes:
    • StandardDelivery
    • ExpressDelivery
  3. Override calculateCharge() in both classes:
    • Standard โ†’ โ‚น50 flat
    • Express โ†’ โ‚น100 flat
  4. In main():
    • Create objects of both types
    • Call the method and display charges

Q3. Encapsulation (Getter/Setter) (10 Marks)

A hospital system needs to protect patient data.

๐Ÿ‘‰ Write a Java program to:

  1. Create a class Patient with:
    • Private variables: patientId, name, age
  2. Provide:
    • Getter and Setter methods
    • Validation: age must be > 0
  3. In main():
    • Set values using setters
    • Display patient details using getters

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


Q4. Abstract Class (10 Marks)

A payment system supports different payment methods.

๐Ÿ‘‰ Write a Java program to:

  1. Create an abstract classPayment:
    • Abstract method pay(double amount)
  2. Create subclasses:
    • CreditCardPayment
    • UPIPayment
  3. Implement the method in both classes:
    • Print payment method and amount
  4. In main():
    • Use reference of abstract class
    • Call methods for both payment types

Q5. Polymorphism (Runtime / Dynamic Method Dispatch) (10 Marks)

A messaging system sends different types of messages.

๐Ÿ‘‰ Write a Java program to:

  1. Create a class Message:
    • Method send()
  2. Create subclasses:
    • TextMessage
    • ImageMessage
  3. Override send() method in both classes:
    • Display appropriate message type
  4. In main():
    • Use parent class reference
    • Assign different child objects
    • Demonstrate runtime polymorphism

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

Q6. Exception Handling

๐Ÿ‘‰ Write a Java program to:

  1. Accept two numbers from user
  2. Perform division
  3. Handle:
    • Division by zero using try-catch
  4. Display appropriate error message

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *