In object-oriented programming, abstraction is all about hiding the implementation details from the user. In the end the user will only know what this function does instead of how it does. One of the way to achieve Java abstraction is through a class contains abstract keyword.
Abstraction is the quality of dealing with ideas rather than events. For example, if we have abstract bank class with one abstract interestRate() method . The definition and logic of calculating interestRate() will be different depending on the bank.
A class contains abstract keyword in declaration known as Abstract class.
// abstract class
abstract class TestClass {
}
Abstract Class Rules:
A Method contains abstract keyword in declaration known as Abstract method. We may have any number of abstract methods in a class.
// abstract class
abstract class TestClass { // abstract method
abstract void addition();
}
Abstract Method Rules:
In the below example, there is a constructor defined with the abstract method print() in the abstract class Shape.
Sub class Circle extends the parent Shape class and override its print() method.
In the Test public class created a Shape object having a Circle class reference to execute the print() method.
OUTPUT:
Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.
📝 Blogs
javadoubts.com © All rights reserved