tutorialcup
Abstraction in Java
What is Abstraction
Abstraction in Java, which is one of the OOPs concepts, is the process of showing only the required information to the user by hiding other details. For example, consider a mobile phone, we just know that pressing on the call button, will dial the required number. But we actually don't know the actual implementation of how a call works. This is because the internal mechanism is not visible to us. This is a real example of abstraction. Similarly, abstraction works in the same way in Object-oriented programming. In this tutorial, we will learn how to achieve abstraction using Java abstract classes and methods.
Ways to achieve Java Abstraction
We can achieve abstraction in java by below 2 ways.
You can refer to Interface in Java tutorial to understand more about achieving abstraction using an interface.
Use of Abstraction
- Provides security by hiding implementation details.
- Provides flexibility for the subclass to implement the functionality of the inherited abstract method of the superclass.
Let's discuss in detail about Java abstract class and methods.
Abstract class in Java
When we declare a class with an abstract keyword, we call it an abstract class. abstract is a non-access modifier keyword that we can use along with a class and method. An abstract class is a special class that is a superclass that contains unimplemented methods. Hence the subclass that inherits the parent abstract class should implement all the abstract methods.
Abstraction in Java
What is Abstraction
Abstraction in Java, which is one of the OOPs concepts, is the process of showing only the required information to the user by hiding other details. For example, consider a mobile phone, we just know that pressing on the call button, will dial the required number. But we actually don't know the actual implementation of how a call works. This is because the internal mechanism is not visible to us. This is a real example of abstraction. Similarly, abstraction works in the same way in Object-oriented programming. In this tutorial, we will learn how to achieve abstraction using Java abstract classes and methods.
Ways to achieve Java Abstraction
We can achieve abstraction in java by below 2 ways.
You can refer to Interface in Java tutorial to understand more about achieving abstraction using an interface.
Use of Abstraction
- Provides security by hiding implementation details.
- Provides flexibility for the subclass to implement the functionality of the inherited abstract method of the superclass.
Let's discuss in detail about Java abstract class and methods.
Abstract class in Java
When we declare a class with an abstract keyword, we call it an abstract class. abstract is a non-access modifier keyword that we can use along with a class and method. An abstract class is a special class that is a superclass that contains unimplemented methods. Hence the subclass that inherits the parent abstract class should implement all the abstract methods.