AD kumaravelu’s Post

Post-17 🚀 Java OOPS – Abstract Class ❓ What is an Abstract Class? An abstract class is a class that cannot be instantiated and is used to provide a base structure for other classes. It can contain: ✔ Abstract methods (without body) ✔ Concrete methods (with body) ✔ Variables ✔ Constructors 📌 Why Use Abstract Class? To provide common functionality to subclasses To achieve abstraction To enforce method implementation in child classes 💡 Example abstract class Vehicle { abstract void start(); // abstract method void stop() { // concrete method System.out.println("Vehicle stopped"); } } class Car extends Vehicle { @Override void start() { System.out.println("Car starts with key"); } } public class Main { public static void main(String[] args) { Vehicle v = new Car(); v.start(); v.stop(); } } 🔍 Explanation Vehicle is an abstract class It cannot be created using new Car provides implementation of start() Abstract class supports both abstract and normal methods 📢 Interview Tips ✔ Abstract class cannot be instantiated ✔ It can have constructors ✔ It can contain both abstract and concrete methods ✔ Used when classes share common behavior #Java #OOPS #AbstractClass #CoreJava #JavaDeveloper #JavaInterview #Programming

To view or add a comment, sign in

Explore content categories