Oct 20 2022 Flashcards

1
Q

What is the syntax of inheritance

A

class Derived : public Base{

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Derived class
-> 1 Default
-> 2 Single Input
Base
-> 3 Default
-> 4 Singe Input
You created object Base no input how are the constructors executed

A

1 then 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Derived class
-> 1 Default
-> 2 Single Input
Base
-> 3 Default
-> 4 Singe Input
You created object Base one input how are the constructors executed

A

1 and 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Derived(int x,int y):Base(x)
{
cout«“Param of Derived “«y«endl;
}

What is this constructor doing

A

Execute Base class on input constructor then run derived class constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A class can be used in two ways , What are the ways

A

A class can be Derived (IsA)
or
Object of that class be used ( hasA)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What type of members can a class have and what are they called collectively

A

Private
Public
Protected

Access Specifiers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Difference between

Private
Public
Protected

A

-> 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the types of inheritance

A

simple
Hiearchial
MultiLevel Inheritance
Multiple Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Multi-path Inheritance

A

Combination of Multiple Inheritance and Hierarchal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Virtual key Word Do in multipath inheritance

A

Removes the ambiguity as to through which path the base base function is coming to the most derived class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

class child : ______ Parent

What are the ways of inheritance

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Generalization vs Specialization

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is function overriding in terms of classes

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do Virtual Functions work in derived class and base class

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do Virtual Functions work in derived class and base class

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is PolyMorphism

A

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

17
Q

What is pure virtual function

A

virtual void start()=0;

Mandatory for child class to override ,

18
Q

What are types of base classes

A

Base class All Concrete -> Reusability
Base class All Concrete + Virtual -> Reusability + Polymorphism
Base class All Virtual -> Polymorphism (interface)

19
Q

What is Abstract class

A
  • 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
20
Q

What is friend function

A

It is a global function that can access the class variable but you need to declare the friend function within the class

21
Q

What is friend class

A

if a class has a hasA relation it can access the private variables