# OOPS

Here are some problem statements covering Object-Oriented Programming (OOP) concepts in Java from basic to advanced:

1. **Class and Object Creation**: Create a class named `Car` with attributes like `make`, `model`, and `year`, and then create an object of this class.
2. **Encapsulation**: Define a class `Employee` with private attributes like `name`, `age`, and `salary`, and provide public methods to access and modify these attributes.
3. **Inheritance**: Create a class `Vehicle` with attributes like `make` and `model`, and then create a subclass `Car` that inherits from `Vehicle`.
4. **Method Overriding**: Define a method `drive()` in both `Vehicle` and `Car` classes, and override it in the `Car` class to provide a different implementation.
5. **Polymorphism**: Create an array of type `Vehicle` and store objects of both `Vehicle` and `Car` classes in it, then call the `drive()` method on each object.
6. **Abstraction**: Create an abstract class `Shape` with an abstract method `calculateArea()`, and then create concrete subclasses like `Circle` and `Rectangle` that implement this method.
7. **Interface Implementation**: Define an interface `Drawable` with a method `draw()`, and then implement this interface in classes like `Circle` and `Rectangle`.
8. **Composition**: Create a class `Engine` with attributes like `horsepower` and `fuelType`, and then include an instance of this class as an attribute in the `Car` class.
9. **Aggregation**: Create a class `Department` with attributes like `name` and `location`, and then include a list of `Employee` objects as an attribute in the `Department` class.
10. **Association**: Create classes `Student` and `Teacher`, and establish a bi-directional association between them (i.e., a student can have multiple teachers, and a teacher can have multiple students).
11. **Dependency**: Define a class `Logger` with a method `log()` that takes a message as parameter, and then use this class in other classes like `Car` and `Employee` to log messages.
12. **Package Creation**: Create packages like `com.company.model`, `com.company.service`, and `com.company.ui`, and then define appropriate classes in each package.
13. **Access Modifiers**: Define attributes with different access modifiers (private, protected, default, public) in a class, and demonstrate their visibility from other classes.
14. **Static Keyword**: Create a static method `calculateArea()` in a class `MathUtil` that calculates the area of a circle, and then call this method without creating an object of `MathUtil`.
15. **Final Keyword**: Declare a final variable `PI` with a value of 3.14 in a class, and demonstrate that its value cannot be changed.
16. **Abstract Classes**: Define an abstract class `Animal` with an abstract method `makeSound()`, and then create concrete subclasses like `Dog` and `Cat` that implement this method.
17. **Interfaces**: Create an interface `Playable` with a method `play()`, and then implement this interface in classes like `Guitar` and `Piano`.
18. **Marker Interfaces**: Create a marker interface `Serializable` with no methods, and then implement it in classes like `Book` and `Customer` to indicate that they can be serialized.
19. **Nested Classes**: Define a nested class `Inner` within a class `Outer`, and demonstrate how to access members of the outer class from the inner class.
20. **Anonymous Classes**: Create an anonymous class that implements an interface or extends a class, and instantiate it inline without giving it a name.
21. **Local Classes**: Define a local class within a method of another class, and demonstrate how to instantiate it and call its methods.
22. **Method References**: Define methods like `printMessage()` and `calculateArea()` in a class, and then create method references to these methods and pass them as arguments to other methods.
23. **Default Methods**: Define an interface `Resizable` with a default method `resize()`, and then implement this interface in classes like `Circle` and `Rectangle`.
24. **Static Methods in Interfaces**: Define an interface `MathOperations` with static methods like `add()` and `subtract()`, and then call these methods without implementing the interface.
25. **Object Cloning**: Implement the `Cloneable` interface in a class like `Person`, and then demonstrate how to create a shallow copy of an object using the `clone()` method.
26. **Object Serialization**: Implement the `Serializable` interface in a class like `Book`, and then demonstrate how to serialize and deserialize objects using `ObjectOutputStream` and `ObjectInputStream`.
27. **Method Overloading**: Create multiple versions of a method like `calculateArea()` in a class `Shape` that accept different types or numbers of parameters.
28. **Method Overriding**: Override methods like `toString()` and `equals()` in a class like `Employee` to provide custom implementations.
29. **Constructor Overloading**: Define multiple constructors in a class like `Person` that 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.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codewithmeiy.gitbook.io/core-java/test-your-knowledge/oops.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
