๐Ÿงพ Java OOP Practical Exam โ€“ Set 4

โฑ๏ธ 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:

  1. Create a class Book with:
    • bookId (int)
    • title (String)
    • author (String)
    • price (double)
  2. Create:
    • A parameterized constructor to initialize all fields
  3. Create a method displayBookDetails() to print all details.
  4. 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:

  1. Create a base class Employee:
    • Method calculateSalary()
  2. Create subclasses:
    • FullTimeEmployee
    • PartTimeEmployee
  3. Override the method:
    • FullTime โ†’ Fixed salary โ‚น30,000
    • PartTime โ†’ โ‚น500 per hour ร— 8 hours
  4. 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:

  1. Create a class Student:
    • Private variables: rollNo, name, marks
  2. Provide:
    • Getter and Setter methods
    • Validation: marks should be between 0 and 100
  3. 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:

  1. Create an interface SmartDevice:
    • Method turnOn()
    • Method turnOff()
  2. Implement the interface in:
    • Fan
    • Light
  3. Define behavior for both methods in each class.
  4. 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:

  1. Create a class Transport:
    • Method calculateFare()
  2. Create subclasses:
    • Bus
    • Train
  3. Override the method:
    • Bus โ†’ โ‚น20 per km
    • Train โ†’ โ‚น10 per km
  4. 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:

  1. Create a file named data.txt
  2. Write student name and marks into the file
  3. Read the file and display content on screen
  4. Handle exceptions properly

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 *