Welcome back to Day 17 of My Automation Journey! โ๐ป
In the previous days, I explored important Java concepts like:
- ๐ Encapsulation
- ๐ฆ Packages
- ๐ Method Overriding
- ๐ Access Modifiers
Today I learned another very important Object-Oriented Programming concept:
โจ Abstraction
I also explored the final keyword and understood how Java statements like:
System.out.println();
actually work behind the scenes.
Letโs break everything down step by step.
๐งฉ What is Abstraction?
Abstraction means hiding implementation details and showing only essential features to the user.
In simple words:
๐ The user only sees what the system does, not how it does it.
Real-life Example ๐ง
When you use an ATM machine:
- You click Withdraw
- Enter amount
- Cash is dispensed
But you donโt see the internal banking logic.
That hidden logic is Abstraction.
โ๏ธ How to Achieve Abstraction in Java
We achieve abstraction using the abstract keyword.
It can be used in:
| Level | Description |
| ------------ | -------------------------- |
| Class Level | Creating an abstract class |
| Method Level | Creating abstract methods |
๐ Abstract Class in Java
An abstract class:
โ Cannot be instantiated directly
โ Can contain abstract methods
โ Can contain normal methods
โ Can have constructors
โ Can have instance variables
Important note:
โ Abstract methods do not have method body.
Example:
public abstract void withdraw();
๐ง Example โ ATM Abstraction
Letโs understand abstraction using an ATM banking example.
Abstract Class
package abstractdemo;
public abstract class ATM {
public abstract void withdraw();
public abstract void balance();
ATM(){
System.out.println("constructor");
}
public void deposit() {
System.out.println("deposit amount 100");
}
}
What we did here
- withdraw() โ abstract method
- balance() โ abstract method
- deposit() โ normal method
constructor โ allowed in abstract class
So an abstract class can contain both abstract and non-abstract methods.
๐ฆ Implementing Abstract Class
Now another class extends ATM and implements the methods.
package abstractdemo;
public class IciciBank extends ATM {
@Override
public final void withdraw() {
System.out.println("withdrawn amount 1000");
}
@Override
public void balance() {
System.out.println("balance amount 5000");
}
}
Here we implemented the abstract methods.
Interesting thing here:
public final void withdraw()
The final keyword prevents further overriding.
๐จโ๐ป User Class
Now we create the main class.
package abstractdemo;
public class User extends IciciBank {
public static void main(String[] args) {
User rajiv = new User();
rajiv.balance();
rajiv.withdraw();
}
}
Output
constructor
balance amount 5000
withdrawn amount 1000
๐ What is System.out.println() in Java?
We use this statement almost everywhere.
But what does it really mean?
System.out.println("Hello");
System
System is a class in Java.
It belongs to:
java.lang package
This package is automatically imported in every Java program.
out
outis a static object of PrintStream class.
It represents the standard output stream.
That means:
๐ Output will be printed in the console.
println()
println() is a method of PrintStream class.
It prints the text and moves the cursor to the next line.
Example:
System.out.println("Hello");
Output
Hello
๐ Final Keyword in Java
The final keyword is used to restrict modification.
It can be applied to:
| Usage | Meaning |
| -------------- | -------------------- |
| Final Variable | Value cannot change |
| Final Method | Cannot be overridden |
| Final Class | Cannot be inherited |
๐งฎ Final Variable Example
final int age = 20;
If we try:
age = 30;
Java will throw a compile-time error.
Because final variables cannot be modified.
๐ง Why Do We Need Object-Oriented Programming?
OOP helps developers write better and scalable code.
Benefits
1๏ธโฃ Easier to understand
2๏ธโฃ Code Reusability (Inheritance)
3๏ธโฃ Flexibility (Polymorphism)
4๏ธโฃ Data Security (Encapsulation)
๐งฑ Four Pillars of OOP
Object-Oriented Programming is built on four main concepts.
1๏ธโฃ Inheritance
2๏ธโฃ Polymorphism
3๏ธโฃ Encapsulation
4๏ธโฃ Abstraction
All these concepts help developers build modular and maintainable applications.
๐ก My Key Learning Today
Today I understood:
โ What abstraction really means
โ How abstract classes work
โ Abstract classes can contain constructors and normal methods
โ How System.out.println() works internally
โ How the final keyword prevents modification
This concept is very important for framework design and large applications.
โจ Final Thoughts
Abstraction is one of the most powerful concepts in Java.
It helps developers hide complexity and expose only necessary functionality, making applications cleaner and easier to maintain.
Day 17 helped me understand how abstraction works both in theory and with real code examples.
See you in Day 18 of My Automation Journey! ๐
๐ค A Small Note
I used ChatGPT to help structure and refine this blog while ensuring the concepts remain aligned with my trainerโs explanations.

Top comments (0)