Explain the concept of Object-Oriented Programming in Java?

Object-Oriented Programming (OOP) is a programming approach that organizes software around objects rather than functions. An object represents a real-world entity and contains both data (attributes) and behavior (methods). OOP helps create modular, reusable, and maintainable applications.

Key Points: • OOP is based on four core principles: Encapsulation, Inheritance, Polymorphism, and Abstraction. • Encapsulation protects data by restricting direct access and exposing it through methods. • Inheritance enables a class to acquire properties and behavior from another class, promoting code reuse. • Polymorphism allows the same method to behave differently based on the object invoking it. • Abstraction hides implementation details and exposes only essential functionality.

Example: In a banking application, an Account object can contain attributes such as accountNumber and balance, along with methods like deposit() and withdraw(). Different account types, such as SavingsAccount and CurrentAccount, can inherit common functionality from a base Account class.

Code Example:

class Account {
    void display() {
        System.out.println("Account Details");
    }
}

class SavingsAccount extends Account {
}

public class Main {
    public static void main(String[] args) {
        SavingsAccount account = new SavingsAccount();
        account.display();
    }
}

Interview Tip: A concise interview answer is:

"Object-Oriented Programming is a programming paradigm that uses objects to model real-world entities. In Java, OOP is based on Encapsulation, Inheritance, Polymorphism, and Abstraction, which help build reusable, maintainable, and scalable applications."