Abstraction

Abstraction refers to the act of representing essential features without including the background details or explanations.

  • Abstraction provides the outside world with only essential information , in a process of representing essential features without including implementation details.
  • Real life example of Abstraction is ATM Machine; All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can’t know internal details about ATM.
  • The concept of abstraction is that we focus on essential quantities rather than specific characteristics of one particular.
  • In Java abstraction is achieved using abstract class or interfaces.An abstract class is defined using abstract keyword.
  • When a class is declared abstract it cannot be instantiated. To use an abstract class you have to inherit it from another class. A class that contains an abstract method should be defined as abstract.
  • An abstract method is a method that is declared without implementation. e.g abstract void ask();
  • Example
abstract class Animal{
         public int age ;
         public abstract int printAge();       //declaration
}
class Dog extends Animal{
        public int printAge(){
                  return age;
       }
}