Welcome to the Java OOP Fundamentals! π This repository is designed for beginners who want to learn the fundamentals of Object-Oriented Programming (OOP) in Java.
- Encapsulation: How to protect data and expose behavior.
- Inheritance: Building relationships between classes.
- Polymorphism: Achieving flexibility with interfaces and overridden methods.
- Abstraction: Defining contracts and shared behavior using abstract classes.
src/com/starterkit/
βββ abstraction/
β βββ Employee.java
β βββ SalariedEmployee.java
β βββ AbstractionDemo.java
βββ encapsulation/
β βββ BankAccount.java
β βββ EncapsulationDemo.java
βββ inheritance/
β βββ Animal.java
β βββ Dog.java
β βββ InheritanceDemo.java
βββ polymorphism/
βββ Shape.java
βββ Circle.java
βββ Rectangle.java
βββ PolymorphismDemo.java
-
Clone this repository:
git clone https://github.com/LamaBimal/Java-OOP-StarterKit.git cd Java-OOP-StarterKit -
Compile all Java files:
mkdir -p out javac -d out $(find src -name "*.java") -
Run any demo class:
java -cp out com.starterkit.encapsulation.EncapsulationDemo java -cp out com.starterkit.inheritance.InheritanceDemo java -cp out com.starterkit.polymorphism.PolymorphismDemo java -cp out com.starterkit.abstraction.AbstractionDemo
- Start with
encapsulation/BankAccount.javato understand private state and controlled mutation. - Move to
inheritance/Animal.javaandinheritance/Dog.javafor parent-child relationships. - Continue with
polymorphism/Shape.javaand implementations to see one interface, multiple behaviors. - Finish with
abstraction/Employee.javato learn abstract class contracts.
Feel free to fork this repo, add your own OOP examples, and open a pull request.