Abstraction – Java Tutorial in Tamil
This blog explain about Abstraction in Java Easy to understand Java Oops concept
Abstraction:-
In the context of Java programming, abstraction is one of the four fundamental principles of object-oriented programming (OOP), along with encapsulation, inheritance, and polymorphism.
Abstraction is “Handling complexity by hiding unnecessary details from the user”
Abstract keyword can be used Methods and Classes, not on Variables.
Java Keyword:-
Abstract
Abstract Class:-
Abstract classes are a concept in object-oriented programming (OOP) that allows you to define common characteristics and behaviors for a group of related classes. An abstract class cannot be instantiated on its own; instead, it serves as a blueprint for other classes. Abstraction classes may contain abstract methods, which are methods without a body, meant to be implemented by the concrete (non-abstract) subclasses.
Here are some key points about abstract classes:
- Cannot be instantiated: You cannot create an instance of an abstract class directly. It is meant to be subclassed by other classes.
- May contain abstract methods: Abstract classes can declare abstract methods, which are methods without an implementation. Concrete subclasses must provide an implementation for these abstract methods.
- May contain concrete methods: Abstract classes can also have fully implemented methods. These methods can be inherited by the subclasses as they are or overridden if needed.
- May contain abstract properties: In addition to methods, abstract classes can declare abstract properties, which are attributes that must be implemented by concrete subclasses.
- Provides a common interface: Abstract classes allow you to define a common interface for a group of related classes, ensuring consistency in the structure and behavior of the subclasses.
- Facilitates code reusability: By providing a common base class, abstract classes promote code reusability. Subclasses can inherit and extend the functionality of the abstract class.
Here’s a simple example in a hypothetical programming language:
public abstract class parent
void grow()
{
System.out.println("healthy Food");
}
abstract void study();
Subclasses of the Shape
class must provide a concrete implementation for the study
method.
Abstract Method:-
Abstract class and does not have a definition (implementation) is called an abstract method.
When we need just the method declaration in a super class, it can be achieved by declaring the methods as abstracts.
Abstract method is also called subclass responsibility as it doesn’t have the implementation in the super class. Therefore a subclass must override it to provide the method definition.
abstract return_type method_name( [ argument-list ] );
As the abstract methods just have the signature, it needs to have semicolon (;) at the end.
An abstract method do not have a body (implementation), they just have a method signature (declaration). The class which extends the abstract class implements the abstract methods.
Reference: chat.openai.com
www.javatpoint.com
www.geeksforgeeks.org