Lecture notes on



Download 232,82 Kb.
bet34/45
Sana07.07.2022
Hajmi232,82 Kb.
#755880
1   ...   30   31   32   33   34   35   36   37   ...   45
Bog'liq
285 OOPS lecture notes Complete-конвертирован

C++ Function Overriding

LECTURE-33


If base class and derived class have member functions with same name and arguments. If you create an object of derived class and write code to access that member function then, the member function in derived class is only invoked, i.e., the member function of derived class overrides the member function of base class. This feature in C++ programming is known as function overriding.




Accessing the Overridden Function in Base Class From Derived Class

To access the overridden function of base class from derived class, scope resolution operator ::. For example: If you want to access get_data() function of base class from derived class in above example then, the following statement is used in derived class.


A::get_data; // Calling get_data() of class A.


It is because, if the name of class is not specified, the compiler thinks get_data() function is calling itself.




Abstract Class


Abstract Class is a class which contains atleast one Pure Virtual function in it. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.




Characteristics of Abstract Class





  1. Abstract class cannot be instantiated, but pointers and refrences of Abstract class type can be created.

  2. Abstract class can have normal functions and variables along with a pure virtual function.

  3. Abstract classes are mainly used for Upcasting, so that its derived classes can use its interface.

  4. Classes inheriting an Abstract Class must implement all pure virtual functions, or else they will become Abstract too.




Download 232,82 Kb.

Do'stlaringiz bilan baham:
1   ...   30   31   32   33   34   35   36   37   ...   45




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish