Embarking on a journey to master Object-Oriented Programming (OOP) in Java? You've arrived at the perfect destination. This extensive guide will walk you through a plethora of Java OOP exercises, complete with solutions. Dive right in, and let's expand your coding prowess!

Before we dive into the exercises, let's briefly refresh some key OOP concepts. Object-Oriented Programming revolves around four main principles: Encapsulation, Inheritance, Polymorphism, and Abstraction. With these fundamentals under our belt, let's proceed to our exercises.

Java OOP Exercises for Beginners
Kickstart your OOP journey with these fundamental exercises. Remember, practice makes perfect.

Let's begin with a simple task: create a Class and its Object.
Exercise 1: Create a 'Dog' Class

Create a Dog class with instance variables like name, age, and breed. Define a method 'bark()' that prints a dog bark sound.
Here's a simple solution: ```java public class Dog { public String name; public int age; public String breed; public void bark() { System.out.println("Woof!"); } } ```
Exercise 2: Inheritance: 'Poodle' Class
Create a Poodle class that inherits from the Dog class. Add a new attribute 'size' (small, medium, large) and a method 'showSize()' that prints the size of the Poodle.

Solution: ```java public class Poodle extends Dog { public String size; public void showSize() { System.out.println("I'm a " + size + " Poodle!"); } } ```
Intermediate Java OOP Exercises
Now that you've got the basics down, let's move on to more complex exercises.
Here's an exercise involving Abstraction and Polymorphism.

Exercise 3: Abstract 'Vehicle' Class &Interface 'Engine'
Create an abstract Vehicle class with an abstract method 'start()'. Create an interface Engine with a method 'run()'. Implement this interface in your Vehicle class.



















Solution: ```java public interface Engine { void run(); } public abstract class Vehicle { protected Engine engine; public abstract void start(); public void setEngine(Engine engine) { this.engine = engine; } } ```
Exercise 4: Polymorphism: 'Car' & 'Motorcycle' Classes
Create Car and Motorcycle classes that extend Vehicle, implementing the 'start()' method uniquely. Create engine types (e.g., 'PetrolEngine' and 'ElectricEngine') and use them in Car and Motorcycle objects.
Solution: ```java public class Car extends Vehicle { public Car(Engine engine) { setEngine(engine); } public void start() { System.out.println("Car starting with engine noise... Vroom!"); } } public class Motorcycle extends Vehicle { public Motorcycle(Engine engine) { setEngine(engine); } public void start() { System.out.println("Motorcycle starting with engine roar... Revv! Revv!"); } } ```
Exploring these exercises has hopefully deepened your understanding of Java OOP. To truly master these concepts, keep practicing and expanding your coding portfolio.