Abstraction Data Hiding Encapsulation in OOP
Abstraction Data Hiding Encapsulation in OOP
and
Encapsulation in OOP
Dr. Kuppusamy .P
Associate Professor / SCOPE
Data Abstraction
• Abstraction is the process of considering essential characteristics of an object that
distinguish it from all other objects.
Need of Abstraction
• Abstraction focuses only on most relevant data of an object to the specific process.
• It hides the background details to reduce the complexity and increase efficiency.
• Offers the greatest flexibility when using ADT(Abstract Data Type) objects in
different situations.
✓ ADT is a type (or class) for objects whose behavior is defined by a set of values and a
set of operations.
✓ ADT specifies only what operations are to be performed but not how these operations
will be implemented.
✓ Also, not specifies how data will be organized in memory and what algorithms will be
used for implementing the operations. It is called “abstract” because it gives an
implementation-independent view.
✓ The process of providing only the essentials and hiding the details is known as
abstraction.
• In java, abstraction is achieved by interfaces and abstract classes. Users can
achieve 100% abstraction using interfaces.
Dr. Kuppusamy P
Abstract classes
➢ Abstract is a non-access modifier in java and applicable for classes, methods but
not variables.
➢ An abstract class is a class that is declared with abstract keyword.
abstract class class-name{
//body of class
}
➢ Abstract class is a restricted class that cannot be used to create objects (to access
abstract class, it must be inherited from another class)
➢ An abstract class may or may not have all abstract methods. Some of them can be
concrete methods.
➢ An abstract class can be instantiated either by a concrete subclass or by defining
all abstract methods along with the new keyword.
Dr. Kuppusamy P
Abstract methods
➢ An abstract method is a method that is declared without implementation.
abstract type method-name(parameter-list);
➢ Abstract method can only be used in an abstract class, and it does not have a body. The
body is provided by the subclass (inherited from).
➢ Thus, making overriding compulsory.
➢ Any class that contains one or more abstract methods must also be declared with abstract
keyword.
➢ An abstract class can have parameterized constructors, and default constructor is always
present in an abstract class.
➢ Concrete Class: A concrete class is a subclass which implements all the abstract method
of its super abstract class. It also has implementations of all methods of interfaces it
implements.
➢ Concrete Method: The methods which are not abstract methods are concrete methods. To
execute concrete methods, create an instance (object) of the class and call to that specific
method.
Dr. Kuppusamy P
Abstract class
• abstract class cannot be instantiated directly
• E.g.,
abstract class Demo {
abstract void display();
}
Dr. Kuppusamy P
Encapsulation vs Data Abstraction
Dr. Kuppusamy P
References
Dr. Kuppusamy P