Abstraction is one of the principle of object oriented programming. It is used to display only necessary and essential features of an object to outside the world.Means displaying what is necessary and encapsulate the unnecessary things to outside the world.Hiding can be achieved by using "private" access modifiers.
We can not create object of an Abstract class we only create reference variable of it thats why abstract class must be inherited by any derived class which want to use the functionality of abstract methods.
Note - Outside the world means when we use reference of object then it will show only necessary methods and properties and hide methods which are not necessary.
We can take an example of an car. We can see the wheels, engine and can hear the horn of an car but we don't know that how they are working. because their internal mechanism is hidden from us we only know that it is working but how we don't know it is type of abstraction.
When we declare any method of a class as abstract then the class becomes Abstract class.
When derived class inherited with abstract class; derived class must be override abstract class methods.
Impementation of Abstarction:
Output:
Galgotiya BTech Fee 50000/-
Galgotiya MBA Fee 100000/-
Galgotiya MBA Fee 100000/-
LPU BTech Fee 40000/-
LPU MBA Fee 800000/-
LPU MBA Fee 800000/-
Explanation :-
From above example we have make one abstract class university and two abstract methods Btech and MBA. Galgotiya and LPU both are override university course fee.
University course common for both Galgotiya and LPU so university method BTech and MBA is abstract.
Galgotiya and LPU inherited abstract method so university method must be override here.
Pure Abstract Class:
When a abstract class have all their method as abstract then the class known as Pure Abstract Class.
0 comments:
Post a Comment