โฑ๏ธ 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:
- Create a class
Mobilewith the following data members:- brand (String)
- model (String)
- price (double)
- Create a parameterized constructor to initialize all values.
- Create a method
displayMobile()to print mobile details. - 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:
- Create a base class
Deliverywith:- Method
calculateCharge()(default implementation)
- Method
- Create two derived classes:
StandardDeliveryExpressDelivery
- Override
calculateCharge()in both classes:- Standard โ โน50 flat
- Express โ โน100 flat
- 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:
- Create a class
Patientwith:- Private variables: patientId, name, age
- Provide:
- Getter and Setter methods
- Validation: age must be > 0
- 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:
- Create an abstract class
Payment:- Abstract method
pay(double amount)
- Abstract method
- Create subclasses:
CreditCardPaymentUPIPayment
- Implement the method in both classes:
- Print payment method and amount
- 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:
- Create a class
Message:- Method
send()
- Method
- Create subclasses:
TextMessageImageMessage
- Override
send()method in both classes:- Display appropriate message type
- 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:
- Accept two numbers from user
- Perform division
- Handle:
- Division by zero using
try-catch
- Division by zero using
- Display appropriate error message