Abstraction and encapsulation

ABSTRACTION AND ENCAPSULATION
 
Abstraction: Abstraction is the technique of hiding the implementation details and showing only functionality to the user. 
 
For example, when we call any person we just dial the numbers and are least bothered about the internal process involved.
 
Abstract class
  • A class that can contain abstract keyword is known as an abstract class.
  • Abstract methods do not have body.
  • It forces the user to extend the implementation rather than modification.
  • An abstract class cannot be instantiated.
Abstract Method
  • If a method is declared as an abstract, then it is called abstract method.
  • It does not have implementation.
  • It contains method signature but not method body.
 
Encapsulation: Encapsulation is the mechanism of binding together variables and functions into a single unit. 
  • Encapsulation is used for information hiding. 
  • Encapsulation can be achieved by declaring variables of class as private.

References:

  1. Sebesta,”Concept of programming Language”, Pearson Edu
  2. Louden, “Programming Languages: Principles & Practices” , Cengage Learning
  3. Tucker, “Programming Languages: Principles and paradigms “, Tata McGraw –Hill.
  4. E Horowitz, “Programming Languages”, 2nd Edition, Addison Wesley
EasyExamNotes © 2023