🎯 If you’re preparing OOPS concepts for university exams, here’s a collection of exercises (with increasing difficulty) that touch all the major OOPS concepts in Java. These are highly exam-relevant and will also boost practical understanding 👇
📝 OOPS Practice Exercises in Java (University/College Level)
1️⃣ Classes and Objects
✅ Easy-level, foundation concept
-
Write a class
Studentwith attributes:name,rollNumber, andmarks.
Create objects ofStudentand display their details. -
Create a class
Carwith propertiesbrand,model, andprice.
Write a methoddisplayInfo()to show car details.
2️⃣ Encapsulation
✅ Testing getters & setters
-
Create a class
BankAccountwith private variables:accountNumber,balance.
Provide getter and setter methods.
Write code to deposit money and check balance.
3️⃣ Inheritance
✅ Shows reusability & parent-child relation
-
Create a class
Personwith attributesname,age.
Derive a subclassEmployeewith attributessalaryanddesignation.
Demonstrate inheritance by creating objects. -
Create a base class
Shapewith methodarea().
Extend classesCircleandRectanglethat overridearea()method.
4️⃣ Polymorphism
✅ Method Overloading & Overriding exercises
-
Overloading: Create a class
Calculatorwith methodsadd(int, int)andadd(double, double). Show method overloading. -
Overriding: Create a class
Animalwith methodsound().
SubclassDogandCatto overridesound().
5️⃣ Abstraction
✅ Abstract classes practice
-
Create an abstract class
Vehiclewith abstract methodstart().
Implement it in subclassesCarandBike.
6️⃣ Interface
✅ Multiple inheritance via interface
-
Create an interface
Paymentwith methodpay().
Implement it in classesCreditCardPaymentandUPIPayment. -
Create two interfaces
CameraandMusicPlayer.
Create a classSmartPhonethat implements both.
7️⃣ Constructor & ‘this’ keyword
✅ Frequently asked in exams
-
Write a program to demonstrate constructor overloading in a
Bookclass. -
Use
thiskeyword to differentiate between class variables and method parameters.
8️⃣ Static Keyword
✅ Important for theory + coding
-
Create a class
Collegewith static variablecollegeName.
Show how all objects share the same static variable. -
Write a program with a static method
displayUniversity()to print a university name.
9️⃣ Real-world Mini Project (Integration of All OOPS)
📌 Often asked as long-answer/15-mark questions
-
Design an E-Commerce Application skeleton in Java:
-
Class
Product(id, name, price). -
Class
Customer(id, name, email). -
Abstract class
Orderwith abstract methodplaceOrder(). -
Subclass
OnlineOrderandOfflineOrderthat overrideplaceOrder(). -
Interface
Paymentwithpay(). ImplementCreditCardandUPI. -
Demonstrate all OOPS principles in action.
-
🎯 Why These Are Exam-Ready?
-
Covers all four pillars: Encapsulation, Inheritance, Polymorphism, Abstraction.
-
Includes syntax-based + application-based questions.
-
Gives both small coding snippets (5–8 marks) and long coding problems (10–15 marks).