Oct 20 2022 Flashcards
(21 cards)
What is the syntax of inheritance
class Derived : public Base{
}
Derived class
-> 1 Default
-> 2 Single Input
Base
-> 3 Default
-> 4 Singe Input
You created object Base no input how are the constructors executed
1 then 2
Derived class
-> 1 Default
-> 2 Single Input
Base
-> 3 Default
-> 4 Singe Input
You created object Base one input how are the constructors executed
1 and 3
Derived(int x,int y):Base(x)
{
cout«“Param of Derived “«y«endl;
}
What is this constructor doing
Execute Base class on input constructor then run derived class constructor
A class can be used in two ways , What are the ways
A class can be Derived (IsA)
or
Object of that class be used ( hasA)
What type of members can a class have and what are they called collectively
Private
Public
Protected
Access Specifiers
Difference between
Private
Public
Protected
-> In main function you can only access public members
-> In a derived function of a derived class you can access public and protected only
-> All Are accessible with in its own class
What are the types of inheritance
simple
Hiearchial
MultiLevel Inheritance
Multiple Inheritance
What is Multi-path Inheritance
Combination of Multiple Inheritance and Hierarchal
What does Virtual key Word Do in multipath inheritance
Removes the ambiguity as to through which path the base base function is coming to the most derived class
class child : ______ Parent
What are the ways of inheritance
Public , all the members keep the original access Modifier
Protected , all the members keep the original access Modifier except for public which becomes protected
Private , all the members private
Generalization vs Specialization
Top-Down = Specialization ( Parent Class was Existing then we defined a base class)
Bottom-Up = Generalization ( Base class was existing then we defined a parent class) -> Purpose is to group to achieve polymorphism
What is function overriding in terms of classes
- Redefining a function of base class in derived class
- Function overriding is used for achieving runtime polymorphism
- Prototype of a overrides function must be exactly same as base class function
How do Virtual Functions work in derived class and base class
- Virtual functions are used for achieving polymorphism
- Base class can have virtual functions
- Virtual functions can be overrides in derived class
- Pure virtual functions must be overrides by derived class
How do Virtual Functions work in derived class and base class
- Virtual functions are used for achieving polymorphism
- Base class can have virtual functions
- Virtual functions can be overrides in derived class
- Pure virtual functions must be overrides by derived class
What is PolyMorphism
Same name different actions
* Runtime Polymorphism is achieved using function overriding
* Virtual functions are abstract functions of base class
* Derived class must override virtual function
* Base class pointer pointing to derived class object and a override function is called
What is pure virtual function
virtual void start()=0;
Mandatory for child class to override ,
What are types of base classes
Base class All Concrete -> Reusability
Base class All Concrete + Virtual -> Reusability + Polymorphism
Base class All Virtual -> Polymorphism (interface)
What is Abstract class
- Class having pure virtual function is a abstract class
- Abstract class can have concrete also.
- Object of abstract class cannot be created
- Derived class can must override pure virtual function, otherwise it will also become a abstract
class. - Pointer of abstract class can be created
- Pointer of abstract class can hold object of derived class
- Abstract classes are used for achieving polymorphism
What is friend function
It is a global function that can access the class variable but you need to declare the friend function within the class
What is friend class
if a class has a hasA relation it can access the private variables