• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Selenium
  • Manual Testing
  • SQL Tutorial For Beginners
  • Difference
  • Tools
  • Contact Us
  • Search
SoftwareTestingo » Java » Java Tutorial » Define Data Abstraction in java & Abstract Class With Real time Example

Define Data Abstraction in java & Abstract Class With Real time Example

Last Updated on: April 23, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • Examples
  • What are the Abstract class and Abstract methods?
  • When to use Abstract method and abstract class?
  • How to achieve abstraction in java?

Define Data Abstraction in java & Abstract Class: In this Java tutorial, we are going to discuss one of the important OOPS concept called Abstraction. It is a property of OOPS by which we are displaying the essential details to the user and non-essential details are not displayed to the user. Let’s take an example of Bike for this user is able to see the complete bike only but the inner implementation is not displayed to the biker.

Examples

We can also say that in this is a process of identifying the required details and ignoring the unnecessary details. let take a real-time example of the bike where the rider only knows how to ride the bike but he does not know when he raised the accelerator or change the gear what’s happening inside of the bike. This is what abstraction is.

In Java, we can achieve the abstraction by using interfaces and abstract classes. If our main motto is to achieve 100% abstraction then we have to use interfaces.

What are the Abstract class and Abstract methods?

  • A Call is called an abstract’ class when that class is declared with an abstract keyword.
  • An abstract method is a method that does have any method body and that method is declared with the keyword Abstract.
  • An Abstract class have all abstract method or it can have also a concrete method (method with method body)
  • An abstract method must be implemented in the subclass otherwise you have to make the subclass also an abstract class.
  • We cannot create an object for an abstract class and an abstract class cannot be instantiated with the new operator.
  • 6 Abstract classes can have a default constructor and parameterized constructor.

When to use Abstract method and abstract class?

Suppose there is a situation where you have the structure than in that place you can create the superclass as the abstract class so we can define methods with the body and some methods without method body. And sometimes we have some general form and that should be shared by all subclasses then, in that case, we can define the superclass as an abstract class and all methods as abstract methods, so that each subclass needs to implement the same abstract methods as per their requirements.

Don’t Miss: Software Testing Interview Questions

If you think about the interview point of view then in most of the interviews you may face a common question that what is the difference between Encapsulation vs. Data Abstraction.

Encapsulation: It’s a process of hiding data (information hiding), where we groups data and methods together which are acted upon the data.

Data Abstraction: It’s the process of details hiding (implementation hiding) that deals with exposing the interface to the end-user and hiding the inner implementation.

Abstraction Advantages:

  • By using abstraction we can able to reduce the complexity of viewing things.
  • We can able to increase the code re-usability and avoid code duplication.
  • One of the important things is that we can increase the security of an application and also available the important details to the user.

How to achieve abstraction in java?

As we know that abstraction is one of the core principles concept of Object-oriented programming language and Java following all OOPs principles, abstraction is one of the major building blocks of java language.

So we can achieve abstraction by using interfaces and an abstract class. by using we can achieve 100% abstraction but if we are using an abstract class then we achieve partially abstraction as well.

Please write comments if you find anything incorrect, or you want to share more information about this topic discussed above then you can use our contact us page.

    Memory Management In Java
    Memory Management In Java
    Bytecode in Java
    What Is Bytecode In Java?
    While Loop In Java
    While Loop In Java With Examples
    What is Java Compiler In Java
    What is Java Compiler In Java?
    LinkedHashMap Class In Java
    LinkedHashMap Class In Java
    Java Iterator
    Java Iterator In Details
    If Statement in Java
    If Statement in Java
    Delete File In Java
    Delete File In Java
    Java Inner Class With Example
    Java Inner Class With Example
    What is JDK (Java Development Kit ) In Java
    What is JDK?

    Filed Under: Java Tutorial

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Footer

    Java Tutorial for Beginners | Selenium Tutorial | Manual Testing Tutorial | SQL Tutorial For Beginners | GitHub Tutorial For Beginners | Maven Tutorial

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers