Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.26 KB

File metadata and controls

48 lines (37 loc) · 1.26 KB

Java OOP Exercises

This project contains a collection of Java Object-Oriented Programming exercises that demonstrate the four main pillars of OOP:

  • Classes
  • Objects
  • Encapsulation
  • Inheritance
  • Polymorphism

Exercises Included

Part 1: Car Class

  • Demonstrates basic class creation with private fields
  • Shows encapsulation through getters and setters
  • Includes a constructor and display method

Part 2: ElectricCar Class

  • Demonstrates inheritance by extending the Car class
  • Adds new fields and methods specific to electric cars
  • Shows method overriding

Part 3: Polymorphism

  • Demonstrates polymorphism through method overloading
  • Shows how a method can work with different types of objects

Part 4: Zoo Application

  • Creates a hierarchy of animal classes
  • Demonstrates method overriding in subclasses
  • Shows how to work with collections of different object types

Bonus Challenge: Shape Classes

  • Creates an abstract Shape class
  • Implements concrete Circle and Rectangle classes
  • Demonstrates abstract methods and inheritance

How to Run

  1. Compile all Java files:

    javac src/*.java
  2. Run the Main class:

    java -cp src Main

The program will demonstrate all the OOP concepts through practical examples.