This repository contains Java programs that demonstrate core Object-Oriented Programming (OOP) concepts along with a collection of basic utility programs for beginners. It is designed to provide hands-on examples for learning and revising Java fundamentals.
java-Oops/
└── java_new/
└── src/
└── com/
└── java/
├── abstraction.java
├── encapsulation.java
├── inheritance.java
├── polymorphism.java
├── user_input.java
└── programes.java
- ✅ Abstraction: Using abstract classes and/or interfaces
- ✅ Encapsulation: Using private fields and public getters/setters
- ✅ Inheritance: Demonstrating base and derived classes
Each file in this section demonstrates one of the four main Object-Oriented Programming principles using Java.
Demonstrates:
- Abstract classes and methods
- Real-world examples with:
animal
class and subclasseslion
andtiger
shape
class and subclassescircle
,Triangle
Bank
class and subclassesSavingsAccount
,CurrentAccount
Key Concepts:
- Abstract methods must be implemented by subclasses.
- You cannot instantiate abstract classes.
Demonstrates:
- Using private variables and public getters/setters for data hiding
- Examples:
person
,BankAccount
,Rectangle
,Employee
,Car
,Student
, andCircle_
classes
Key Concepts:
- Encapsulation protects internal data by exposing controlled access via getter and setter methods.
- Promotes modularity and maintainability.
Demonstrates:
- Single-level inheritance with classes
father
→childern
- Method overriding with
Animal
andCat
classes
Key Concepts:
- Subclasses inherit fields and methods from their parent classes.
- Overriding allows a subclass to provide a specific implementation of a method.
Demonstrates:
- Compile-time Polymorphism (Method Overloading) — not present directly but can be extended
- Run-time Polymorphism (Method Overriding) using:
Animalfamily
→bird
,cat_
shapes
→circle_shape
,rectangle
Key Concepts:
- Polymorphism allows the same method to behave differently depending on the object calling it.
- Enhances flexibility and reusability of code.
- Coin toss simulation
- Leap year check
- Finding factors of a number
- Quotient and remainder
- Swapping numbers
- Even or odd check
- Vowel or consonant check
- Finding the largest among three numbers
- Printing squares (power of 2)
- Harmonic number series
The user_input.java
file demonstrates usage of the Scanner
class to take various types of user input and perform basic operations like:
- Name confirmation loop
- Sum and product of integers
- Rectangle area calculation
- Printing user profile (name, roll number, interest)
- Square of a number
- Concatenating strings
- Perimeter of a square
- Equality check among three numbers
- Condition checking using
if-else
- Marks input with validation (max 100 per subject)
- Percentage calculation
-
Clone the repo:
git clone https://github.com/your-username/java-Oops.git
-
Navigate to the source folder:
cd java-Oops/java_new/src
-
Compile and run a Java file:
javac com/java/Programs.java java com.java.Programs
Make sure your terminal is in the
src
directory so the package paths resolve correctly.
- Java beginners learning OOP
- Students practicing for exams or interviews
- Quick revision of Java fundamentals through examples