OBJECT-ORIENTED PROGRAMMING THROUGH JAVA(24CS204)
Academic Year :2025 – 26, II YR – I SEM
Module -1 Question Bank
1.
a) Discuss a Java program to manage a store’s inventory using an array of products.
Each product must have a product ID, name, quantity, and price as attributes.
Implement a method to display the entire inventory with all product details.
Add functionality to insert new products into the inventory with proper validation.
b) Analyze a method to search for a product using its product ID and display the result.
Add a method to update the quantity of a selected product in the inventory array.
Write logic to calculate and return the total inventory value based on quantity × price.
These operations help develop analytical thinking using conditionals and iterations.
c) Develop a method to sort inventory by product name in alphabetical order.
Write a method to find and display product(s) with the highest price in the inventory.
Implement functionality to remove a product by ID from the inventory array.
This part enhances problem-solving skills with array manipulation and custom logic.
2.
a) Discuss a Java class BankAccount with attributes: accountNumber, balance, and
ownerName.Implement a constructor to initialize the account and create getter
methods. Add methods for deposit(double amount) and withdraw(double amount)
operations. Ensure the structure uses proper encapsulation and demonstrates class
design understanding.
b) Apply a custom exception class named InsufficientFundsException to handle low
balancecases.Modify the withdraw() method to throw this exception when the balance
is insufficient. Perform valid and invalid withdrawals to test the exception mechanism.
Demonstrate how Java handles exceptions using try-catch blocks in the main method.
c) Create a BankAccount object and deposit an initial amount.
Withdraw an amount less than the balance, and then try withdrawing more than the
balance.Print the final account balance and display custom error messages if
exceptions occur. Design the code to be user-friendly and robust for different
transaction scenarios.
3.
a) Describe an abstract class MediaPlayer with common attributes like name, duration, and
volume.Include abstract methods such as play(), pause(), and stop() for all media types.
Implement two subclasses: AudioPlayer and VideoPlayer with media-specific behaviors.
Override necessary methods in each subclass to implement type-specific playback
functionality.
b) Apply a MusicPlayerApplication class that manages multiple media players using a
collection. Provide methods to add media player objects and display their information in a
formatted manner. Include functionality to play, pause, stop, and adjust volume for any
media playerinstance.Demonstrate how inheritance and polymorphism help in managing
different media types uniformly.
c) Design the extend application with user-friendly features such as repeat mode, shuffle, or
equalizer settings. Allow media player objects to support customizable playback options
based on user preferences. Encourage creativity by defining additional methods or UI
interactions for these customsettings. Ensure modular design and clear user interaction flow to
support extensibility of the application.
4.
a) Illustrate a Student class with private fields for name, ID, and GPA.
Provide public getter methods and an updateGPA(double gpa) method with validation
logic.Ensure GPA can only be updated if it’s within the valid range of 0.0 to 4.0.This
promotes encapsulation and controlled access to sensitive data.
b) Analyze a program that simulates memory leaks by storing objects in a list without
removing them. Use strong references to retain unnecessary objects beyond their
lifecycle. After simulating, display the total number of objects still occupying memory.
This helps demonstrate how memory can be misused in large-scale applications.
c) Develop memory leaks by nullifying references or clearing unused object lists.
Use Java tools like VisualVM or Java Mission Control to analyze memory usage.
These tools help identify memory-retaining objects and track heap growth.
Effective garbage collection techniques help improve performance and resource use.
5.
a) Describe an abstract class Animal with abstract methods eat(), makeSound(), and
move().Define general attributes and enforce all subclasses to implement these behaviors.
Design Mammal, Bird, and Reptile classes that inherit from Animal.
Each subclass should override methods and have specific attributes like breed.
b) Analyze Instantiate animals like Lion, Sparrow, and Snake using the appropriate
subclasses. Implement unique behavior for each — e.g., flying for birds, crawling for
reptiles.Use getters and method calls to simulate and print their actions like eating and
movingand how method overriding supports behavior polymorphism in the zoo system.
c) Evaluate a ZooSystem driver class to showcase different animal objects and their behavior.
Use method calls to trigger eat(), makeSound(), and move() on each animal.
Ensure proper use of inheritance, abstract methods, and dynamic method dispatch.
This task encourages creativity and structure in showcasing real-world class design.
6.
a) Elaborate a base class Shape with a method calculateArea() to define shape behavior.
Create subclasses Rectangle and Circle that extend Shape and override calculateArea().
Use appropriate formulae for area of a rectangle and circle in each subclass.
This task helps understand inheritance and method overriding in OOP.
b) Compare objects of Rectangle and Circle and reference them using the Shape class.
Invoke calculateArea() using dynamic method dispatch (polymorphism).
Store and display calculated areas of both shapes in a clear, formatted output.
Analyze how polymorphism enables flexible and reusable design.
c) Design messages for each shape (e.g., "Circle Area: ...") during area calculation.
Allow customization like user input or fixed values for dimensions during testing.
Demonstrate a real-world feel by presenting the solution as part of a classroom activity.
Encourage code reuse and clean method structure across shape classes.
7.
a) Illustrate a String class which offer complex string operations, such as searching,
replacing, pattern matching, and substring extraction, for accommodating advanced
user requirements.
Example: Consider the following example to illustrate the advanced functionality of the
application:
Input: String: "The quick brown fox jumps over the lazy dog"
Operation 1: Replace "fox" with "cat"
Operation2: Extract all words starting with "q" and ending with "k"
Operation 3: Delete all the words starting with "q"
b) Analyse various Pattern Matching Procedures which are used in Search Engines
Like Google, yahoo,Bing….
c) Evaluate conversation between two friends, one friend is unaware of the surname of the
other. To resolve this, the friend asks the other person about their name. The person
responds with a string, a, which is a combination of their surname and name. However,
the string a is in the following format: "shsharifaik", where the name is "sharif" and the
surname is "shaik".
8.
a) Describe a Java program that manages a collection of customer objects. Each customer
object consumes a significant amount of memory due to its associated data. Keep adding
the customers’ data. Over time, you observe that the program's memory usage keeps
increasing, potentially indicating memory leaks. (To check a Java program's memory
usage, you can use Java's built-in management and monitoring tools, such as the Java
Virtual Machine (JVM) Tool Interface (JVM TI), Java Management Extensions (JMX),
or external profiling tools like VisualVM or Java Mission Control.).
b) Analyze and address this issue using garbage collection techniques in Java?
c) Develop a step-by-step approach along with specific strategies you would employ in
your investigation.
9.
a) Discuss an abstract class Animal with abstract methods: eat(), makeSound(), and
move().Create subclasses Mammal, Bird, and Reptile to implement the specific
behaviors. Each subclass should override the methods to reflect its unique
characteristics. This structure demonstrates abstraction and polymorphism in animal
behavior modeling.
b) Apply one object each for Mammal, Bird, and Reptile classes.
Invoke overridden methods to display unique sound, eating, and movement behavior. Use
polymorphism to treat all objects as type Animal while showing subclass output. This
proves dynamic method dispatch and real-time method resolution.
c) Create packages: customers, products, and orders for e-commerce organization.
Define one class per package with relevant fields and access modifiers.
Use methods to interact between packages for adding and processing orders.
This approach improves code maintainability, clarity, and modular development.
10.
Design and implement a Java program that fulfills the following requirements:
a) Illustrate a base class called User with attributes like username, email, and password.
Implement methods for user registration, login, and profile management, including
updating the email and password.
b) Analyze a subclass called Customer that inherits from the User class. Add additional
attributes like name, address, and contact information specific to customers. Customers
should be able to view and update their profile information, such as the name and
address. Implement appropriate methods to handle these operations. Implement another
subclass called Admin that also inherits from the User class. Admins have additional
privileges compared to customers, such as the ability to manage user accounts. Admins
should be able to view and update customer profiles, as well as create or delete
customer accounts. Implement methods to support these admin-specific functionalities.
c) Evaluate a secure password encryption mechanism, such as using hashing algorithms
(e.g., bcrypt or SHA-256), to store and compare user passwords securely. Ensure that the
passwords are not stored in plain text format. role-based access control to restrict certain
functionalities based on user roles