โฑ๏ธ Time: 2 Hours
๐ Maximum Marks: 50
๐ Instructions:
- Attempt all questions.
- Follow proper OOP concepts strictly.
- Use meaningful class, method, and variable names.
- Include comments for clarity.
- Output should be well-formatted.
๐น Section A โ Core Programming (30 Marks)
Q1. Class, Object & Constructor (10 Marks)
A bookstore wants to store details of books.
๐ Write a Java program to:
- Create a class
Bookwith:- bookId (int)
- title (String)
- author (String)
- price (double)
- Create:
- A parameterized constructor to initialize all fields
- Create a method
displayBookDetails()to print all details. - In
main():- Create at least 3 book objects
- Display their details
Q2. Inheritance & Method Overriding (10 Marks)
A company calculates employee salaries differently.
๐ Write a Java program to:
- Create a base class
Employee:- Method
calculateSalary()
- Method
- Create subclasses:
FullTimeEmployeePartTimeEmployee
- Override the method:
- FullTime โ Fixed salary โน30,000
- PartTime โ โน500 per hour ร 8 hours
- In
main():- Create objects of both types
- Call the method and display salary
Q3. Encapsulation (10 Marks)
A student record system must protect marks data.
๐ Write a Java program to:
- Create a class
Student:- Private variables: rollNo, name, marks
- Provide:
- Getter and Setter methods
- Validation: marks should be between 0 and 100
- In
main():- Assign values using setters
- Display details using getters
๐น Section B โ Advanced OOP Concepts (20 Marks)
Q4. Interface (10 Marks)
A smart home system controls different devices.
๐ Write a Java program to:
- Create an interface
SmartDevice:- Method
turnOn() - Method
turnOff()
- Method
- Implement the interface in:
FanLight
- Define behavior for both methods in each class.
- In
main():- Create objects of both classes
- Call methods using interface reference
Q5. Polymorphism (Method Overriding) (10 Marks)
A transport system calculates fare differently.
๐ Write a Java program to:
- Create a class
Transport:- Method
calculateFare()
- Method
- Create subclasses:
BusTrain
- Override the method:
- Bus โ โน20 per km
- Train โ โน10 per km
- In
main():- Use parent class reference
- Assign child class objects
- Demonstrate runtime polymorphism
โญ Bonus Question (Optional โ 5 Marks)
Q6. File Handling
๐ Write a Java program to:
- Create a file named
data.txt - Write student name and marks into the file
- Read the file and display content on screen
- Handle exceptions properly