OOPS
Here are some problem statements covering Object-Oriented Programming (OOP) concepts in Java from basic to advanced:
Class and Object Creation: Create a class named
Carwith attributes likemake,model, andyear, and then create an object of this class.Encapsulation: Define a class
Employeewith private attributes likename,age, andsalary, and provide public methods to access and modify these attributes.Inheritance: Create a class
Vehiclewith attributes likemakeandmodel, and then create a subclassCarthat inherits fromVehicle.Method Overriding: Define a method
drive()in bothVehicleandCarclasses, and override it in theCarclass to provide a different implementation.Polymorphism: Create an array of type
Vehicleand store objects of bothVehicleandCarclasses in it, then call thedrive()method on each object.Abstraction: Create an abstract class
Shapewith an abstract methodcalculateArea(), and then create concrete subclasses likeCircleandRectanglethat implement this method.Interface Implementation: Define an interface
Drawablewith a methoddraw(), and then implement this interface in classes likeCircleandRectangle.Composition: Create a class
Enginewith attributes likehorsepowerandfuelType, and then include an instance of this class as an attribute in theCarclass.Aggregation: Create a class
Departmentwith attributes likenameandlocation, and then include a list ofEmployeeobjects as an attribute in theDepartmentclass.Association: Create classes
StudentandTeacher, and establish a bi-directional association between them (i.e., a student can have multiple teachers, and a teacher can have multiple students).Dependency: Define a class
Loggerwith a methodlog()that takes a message as parameter, and then use this class in other classes likeCarandEmployeeto log messages.Package Creation: Create packages like
com.company.model,com.company.service, andcom.company.ui, and then define appropriate classes in each package.Access Modifiers: Define attributes with different access modifiers (private, protected, default, public) in a class, and demonstrate their visibility from other classes.
Static Keyword: Create a static method
calculateArea()in a classMathUtilthat calculates the area of a circle, and then call this method without creating an object ofMathUtil.Final Keyword: Declare a final variable
PIwith a value of 3.14 in a class, and demonstrate that its value cannot be changed.Abstract Classes: Define an abstract class
Animalwith an abstract methodmakeSound(), and then create concrete subclasses likeDogandCatthat implement this method.Interfaces: Create an interface
Playablewith a methodplay(), and then implement this interface in classes likeGuitarandPiano.Marker Interfaces: Create a marker interface
Serializablewith no methods, and then implement it in classes likeBookandCustomerto indicate that they can be serialized.Nested Classes: Define a nested class
Innerwithin a classOuter, and demonstrate how to access members of the outer class from the inner class.Anonymous Classes: Create an anonymous class that implements an interface or extends a class, and instantiate it inline without giving it a name.
Local Classes: Define a local class within a method of another class, and demonstrate how to instantiate it and call its methods.
Method References: Define methods like
printMessage()andcalculateArea()in a class, and then create method references to these methods and pass them as arguments to other methods.Default Methods: Define an interface
Resizablewith a default methodresize(), and then implement this interface in classes likeCircleandRectangle.Static Methods in Interfaces: Define an interface
MathOperationswith static methods likeadd()andsubtract(), and then call these methods without implementing the interface.Object Cloning: Implement the
Cloneableinterface in a class likePerson, and then demonstrate how to create a shallow copy of an object using theclone()method.Object Serialization: Implement the
Serializableinterface in a class likeBook, and then demonstrate how to serialize and deserialize objects usingObjectOutputStreamandObjectInputStream.Method Overloading: Create multiple versions of a method like
calculateArea()in a classShapethat accept different types or numbers of parameters.Method Overriding: Override methods like
toString()andequals()in a class likeEmployeeto provide custom implementations.Constructor Overloading: Define multiple constructors in a class like
Personthat accept different numbers or types of parameters.
These problem statements cover a wide range of OOP concepts in Java, from basic class and object creation to more advanced topics like nested classes, lambda expressions, and object serialization.
Last updated
Was this helpful?