QA Interview Handbook
  • 🏠Home Page
  • About Testing
    • 💖Qualities of A Great Tester
  • Manual Testing
    • 💡Overview
      • ✋Demand for Software Testing
      • 😄Tester's Role in Manual Testing
      • 7️Testing Principles
      • 🚨V & V
      • ❔Interview Questions
    • ♻️SDLC
      • 📒Phase 1: Planning
      • 🔍Phase 2: Requirement Analysis
      • 👔Phase 3: Design
      • ⛑️Phase 4: Development
      • 🧪Phase 5: Testing
      • 🚚Phase 6: Deployment
      • 🖱️Phase 7: Maintenance
      • ⚔️Common Challenges
      • ❔Interview Questions
    • 🌀STLC
    • 🌊Waterfall
    • ✳️Agile
      • 😁Tester's Role in Scrum
    • 🔢Types
      • ⬜White Box Testing
      • ⬛Black Box Testing
        • 🔰Techniques Used in Black Box Testing
        • 🚘Functional Testing
          • 1️⃣Unit Testing
          • 2️⃣Integration Testing
            • 🔰Techniques Used in Integration Testing
          • 3️⃣System Testing
            • 📼Types of System Testing
            • 🌊Phases of System Testing
            • 🌀Regression Testing
            • 🌫️Smoke Testing
          • 4️⃣Acceptance Testing
            • ⚙️User Acceptance Testing
            • 🅰️Alpha Testing
            • 🅱️Beta Testing
        • 🕳️Non Functional Testing
      • 📑Grey Box Testing
    • 🪄User Story
      • ⏺️Sample User Stories
    • 📓Test Cases
      • ⏺️Sample Test Cases
      • ❔Interview Questions
    • ✖️Defect Life Cycle
      • ☣️Priority + Severity
      • ⏺️Sample Defect Reports
      • ❔Interview Questions
      • 🐛Buggy Questions
    • 🌐Atlassian JIRA
      • 🐞JIRA Issues
      • ❔Interview Questions
    • ❔Interview Questions
  • Accessibility Testing
    • 💡Overview
    • 🤓Tester's Role in Accessibility Testing
    • 📚WCAG Principles
      • 👁️Perceivable
      • 🏹Operable
      • 🧠Understandable
      • 🤖Robust
    • 🔧Axe DevTools
      • ❔Interview Questions
    • 📓Test Cases
    • ❔Interview Questions
  • API Testing
    • 💡Overview
    • 😀Tester's Role in API Testing
    • 🍊HTTP Methods & CRUD
      • 🍂HTTP Status Codes
    • 🍍API Tools
      • 🟠Postman
        • ☄️Sending your first API request
        • 🔬HTTP Requests with Java
        • 🎲GitHub Sample
        • ❔Interview Questions
      • ⛑️REST Assured
        • 🎇Dependency
        • ❔Interview Questions
    • 📓Test Cases
    • 🦧API Cheatsheet
    • ❔Interview Questions
  • Database Testing
    • 💡Overview
    • 😆Tester's Role in Database Testing
    • 🔵SQL
      • ⛓️Constraints
      • 🛢️Referencing a Column
      • 🔼DDL Commands
      • 🔼DML Commands
        • 🖌️Operators
        • 🛠️Functions
          • ⏯️Aggregate Functions
        • 🎅Clauses
          • ⏫Join Clauses
          • 🔵Filter Clauses
          • ⏬Set Operations
      • 🃏Wildcard Character
      • ❔Interview Questions
    • 📓Test Cases
    • 🧤SQL Practice Sites
    • 🫐SQL Cheatsheet
    • ❔Interview Questions
  • Java
    • ⛩️Introduction
    • 😄Tester's Reason to Learn Java
    • Ⓜ️Main Method
      • ❔Interview Questions
    • 📐Variables & Types
      • 🪢Special Types
    • 🥁Modifiers
    • 🅾️Operators
    • 🪡String
      • 🩺String Methods
        • String Method Problems
      • 🚨Delimiter
      • ❔Interview Questions
    • 🖇️Conditionals
      • 💎Common If Statements
      • 💎Common Ternary Operator Statements
    • Ⓜ️Math Class
    • 🌊Loops
      • 💎Common Loop Examples
      • 🔃Nested For Loops
    • 🍼OOPS
      • 🏛️Classes and Objects
        • ❔Interview Questions
      • 🎃Constructor
        • ⚡Static
          • ❔Interview Questions
        • 📍This() & Super()
          • ❔Interview Questions
        • 🍀Finalization
      • 🔓Encapsulation
      • 🐥Inheritance
      • 🦋Polymorphism
      • 🕸️Abstraction
    • 🏮Java Practice Sites
    • ☑️Data Structures + Algorithms
      • 🅾️Big O
      • ☑️Data Structures
        • 🔸Array
        • 🔳Array Problems
        • Page
      • 🪟Sliding Window Technique
        • 🪟Sliding Window Problems
        • 🥐LeetCode #53
        • 🥐LeetCode #209
    • ❔Interview Questions
  • Automation Testing
    • 🚰Flow
      • 💡Overview
      • 🤩Tester's Role in Automation Testing
      • 🍀Selenium
        • 🕸️Selenium WebDriver
          • 🕷️WebDriver Commands
            • 🌐WebElement
              • 🔆HTML Tags
              • 🔬Find Element(s)
              • 🦎Locators
                • ❌Xpath
                • 🏰CSS Selector
                • 📀DOM
                • 🏠Quick Reference for XPath + CSS
            • ✋Waits
            • Browser Management
            • 🏎️Navigation
            • Alerts
          • 🏷️Advanced User Interactions
            • 🗯️Action vs. Actions
            • 💧Drop Down
            • ✅Check Box
            • 🖇️Forms
          • ⚠️Exceptions
        • 🍏OOPS + Selenium
        • 🚢Frameworks
          • ⚓Module Based Framework
          • 🎹Keyword Driven Framework
          • 🎋Data Driven Framework
          • 🌺Hybrid Framework
          • 🌴Log4j
          • 📄Page Object Model
        • 🧪Testing Frameworks
          • 💡TestNG
          • 🉑JUnit
          • 🥒BDD
            • 🥒Cucumber
        • 🌉Selenium Grid
          • ✖️Desired Capabilities
        • ❔Interview Questions
      • 🔄API Testing with Selenium
      • ⏪Database Testing with Selenium
      • Ⓜ️Maven
      • 🐙Git
        • ❔Interview Questions
      • 🕵️‍♂️Jenkins
        • ❔Interview Questions
      • 🐳Docker
        • ❔Interview Questions
      • 📙AWS
        • ❔Interview Questions
  • Behavioral
    • 📣Mixed Interview Questions
    • ⭐STAR Method
      • 🌟Sample Responses
Powered by GitBook
On this page
  • Ways to Achieve Abstraction
  • 📚 Rules for Abstraction in Java 📚
  • 🖼️ Rules for Abstract Classes 🖼️
  • 📑 Rules for Interfaces 📑
  • Difference between abstract class and interface

Was this helpful?

  1. Java
  2. OOPS

Abstraction

Hide the Details, Show the Essence ✨

Abstraction in Java is about hiding implementation details 🙈 and only exposing essential functionality to users. 💡

It helps reduce complexity 😅 and allows focusing on what an object does rather than how it does it. 🔍

Ways to Achieve Abstraction

// Abstract Class 
public abstract class Animal {
  public abstract void makeSound(); // Abstract method
}

// Interface 
public interface Flyable {
  public void fly(); // Interface method
}
  • Abstract Classes 🏫

    • 0-100% abstraction

    • Can have concrete methods 👍

  • Interfaces ⛓️

    • 100% abstraction

    • Cannot have concrete methods ❌

Benefits 🎁

  • Isolates impact of changes 💪

  • Promotes reusability 🙌

  • Enables focus on essentials 🎯

Abstraction is key to managing complexity in large systems! 🚀

📚 Rules for Abstraction in Java 📚

Abstraction refers to hiding implementation details and only exposing functionality to users. In Java, abstraction is achieved through abstract classes and interfaces.

🖼️ Rules for Abstract Classes 🖼️

Abstract classes have the following rules:

  • An abstract class cannot be instantiated directly

  • An abstract class may or may not contain abstract methods

  • Abstract methods only declare the method signature and do not provide an implementation

  • Subclasses must override all abstract methods by providing implementations

For example:

public abstract class Shape {

  public abstract void draw();

}

public class Circle extends Shape {

  @Override
  public void draw() {
    // code to draw a circle
  }

} 

Shape is an abstract class with an abstract draw() method. Circle overrides draw() to provide an implementation.

📑 Rules for Interfaces 📑

Some key rules for interfaces are:

  • An interface cannot be instantiated directly

  • An interface can only contain abstract methods and static constants

  • Methods in an interface are implicitly abstract and public

  • Classes must override all interface methods when implementing an interface

For example:

public interface Drawable {
  
  void draw();

}

public class Square implements Drawable {

  @Override
  public void draw() {
    // code to draw a square
  }

}

The Drawable interface enforces a draw() contract. Square implements Drawable and overrides draw().

So these are the key rules around using abstraction in Java through abstract classes and interfaces.

Difference between abstract class and interface

Abstract class and interface both are used to achieve abstraction where we can declare the abstract methods. Abstract class and interface both can't be instantiated.

But there are many differences between abstract class and interface that are given below.

Abstract class
Interface

1) Abstract class can have abstract and non-abstract methods.

Interface can have only abstract methods. Since Java 8, it can have default and static methods also.

2) Abstract class doesn't support multiple inheritance.

Interface supports multiple inheritance.

3) Abstract class can have final, non-final, static and non-static variables.

Interface has only static and final variables.

4) Abstract class can provide the implementation of interface.

Interface can't provide the implementation of abstract class.

5) The abstract keyword is used to declare abstract class.

The interface keyword is used to declare interface.

6) An abstract class can extend another Java class and implement multiple Java interfaces.

An interface can extend another Java interface only.

7) An abstract class can be extended using keyword "extends".

An interface can be implemented using keyword "implements".

8) A Java abstract class can have class members like private, protected, etc.

Members of a Java interface are public by default.

9)Example:

public abstract class Shape{ public abstract void draw(); }

Example: public interface Drawable{ void draw(); }

Simply, abstract class achieves partial abstraction (0 to 100%) whereas interface achieves fully abstraction (100%).

PreviousPolymorphismNextJava Practice Sites

Last updated 1 year ago

Was this helpful?

🍼
🕸️