Veda Bites are swipeable micro-lessons — each one teaches exactly one
idea. The bites below come from this kit — swipe through them in the app.
💡 Key Idea
Abstraction: Hide Complexity, Show Essentials
What you see is what you need.
Abstraction is the process of hiding implementation details and exposing only essential features to the user. In Java, abstraction is achieved using abstract classes and interfaces.
↳ Abstraction lets you drive a car without knowing how the engine works.
📖 Definition
Abstract Class: Partial Abstraction
A class that can't be instantiated.
An abstract class is declared with the `abstract` keyword. It can have both abstract methods (without body) and concrete methods (with body). You cannot create objects of an abstract class.
↳ Abstract classes provide a common base with some shared code.
📖 Definition
Interface: Pure Abstraction Contract
A blueprint of what a class must do.
An interface is a reference type that contains only abstract methods, default methods, static methods, and constants. It specifies a contract that implementing classes must follow.
↳ Interfaces define capabilities without dictating implementation.
⚖️ Comparison
Abstract Class vs Interface
When to use which?
↳ Use abstract class for shared code; interface for capability contract.
⭐ Important Fact
Abstract Methods Have No Body
Declaration only, no implementation.
An abstract method is declared without an implementation (no curly braces). It must be overridden by the first concrete subclass. If a class contains any abstract method, the class itself must be declared `abstract`.
↳ Abstract methods force subclasses to provide specific behavior.
⚙️ Process
How to Implement Abstraction
Steps to abstract in Java.
↳ Abstraction is a design process, not just a keyword.
✏️ Example
Real-World Example: Payment System
Different payments, same interface.
The `Payment` interface abstracts the payment process. Client code can call `pay()` without knowing the specific payment method.
↳ Abstraction allows swapping implementations without changing client code.
⚠️ Common Mistake
Common Mistake: Forgetting to Override
Abstract methods must be implemented.
↳ Always implement inherited abstract methods in concrete classes.
🎯 Exam Tip
Exam Tip: Abstract vs Interface Keywords
Remember the syntax differences.
↳ Use `extends` for abstract classes, `implements` for interfaces.
🧠 Memory Trick
Memory Trick: IS-A vs CAN-DO
Abstract class = IS-A, Interface = CAN-DO.
Use an abstract class when the subclass IS-A more specific type (e.g., `Car` IS-A `Vehicle`). Use an interface when the subclass CAN-DO something (e.g., `Car` CAN-DO `Drivable`).
↳ IS-A for identity, CAN-DO for capability.
❓ Did You Know
Did You Know? Interfaces Can Have Default Methods
Java 8 added default methods.
Since Java 8, interfaces can have default methods (with implementation) and static methods. This allows adding new methods to interfaces without breaking existing implementations.
↳ Default methods maintain backward compatibility.
✅ Best Practice
Best Practice: Program to an Interface
Code to the contract, not the implementation.
Always declare variables using the interface or abstract class type, not the concrete class. This makes your code more flexible and easier to change.
↳ Interface-based programming reduces coupling.