Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

27 June 2016

Interview Preparation

Lecture: 7 - Object Oriented Programming

Ankush Singla

Doubts?

Feedback on Submission Tool?

Test3

Objective Questions

Object Oriented Programming

C++ Classes

1.
2.
3.

Classes & Objects


Data
Functions

Access Modifiers

1.
2.
3.

Public
Protected
Private

Friend functions & classes

Default methods with every class

10

Constructor and Default Methods

1.
2.
3.
4.

Constructor
Copy Constructor
Copy Assignment Operator
Destructor

11

User Defined Constructors

12

Initializer List

13

Const variables & const functions

14

Operator Overloading
class pair
{
public:
int x,y;
bool operator < ( const pair& p ) const
{
if(x==p.x) return y<p.y;
return x<p.x;
}
};
15

Components of OOP

1.
2.
3.

Encapsulation
Inheritance
Polymorphism

16

Encapsulation

1.
2.
3.

Bind the data and functions together


Hiding the implementation details
Lets us change the implementation
without breaking code of our users

17

Inheritance

1.
2.
3.

Extending Functionality of an existing


class
Add new methods and fields to derived
class
If both classes have a function with same
name, which classs function will get
called?

18

Public, Protected & Private Inheritance

19

Polymorphism

1.
2.
3.
4.

Overriding the base class


functions(Virtual Functions)
Ability of a variable to take different
forms
Ability of a function to behave differently
on basis of different parameters
Ability of a function to work with
parameters of subtypes

20

Virtual Function?

21

Add two numbers in base 14

22

Abstract functions
(Pure Virtual)

23

Abstract Classes(Interfaces)

24

Data Member Modifiers

1.
2.
3.
4.
5.

Public
Protected
Private
Const
Static

25

Function Modifiers

1.
2.
3.
4.
5.
6.
7.

Public?
Protected?
Private?
Virtual
Pure Virtual?
Const
Static

26

Multiple Inheritance

27

Multiple Inheritance

Teacher

Student

TA

28

Multiple Inheritance
class Teacher: public Person, public Employee
{
private:
int m_nTeachesGrade;
public:
Teacher(std::string strName, std::string strEmployer,
double dWage, int nTeachesGrade)
: Person(strName), Employee(strEmployer,
dWage), m_nTeachesGrade(nTeachesGrade)
{
}
};
29

Diamond Problem

30

Templates

31

Lets make a template and use it

32

Template Methods

33

How to bound the allowed types?

34

Exceptions

35

Exceptions & the call stack

36

Try catch block?

Type of Exceptions

1.
2.

Std::exception
Any type you want to throw

38

How to create our own Exception


Class?

SQL

SQL Queries

1.
2.
3.
4.
5.
6.
7.
8.
9.

Create Database
Create Table
Alter Table
Insert data
Select Data
Delete data
Like Queries
Order By
Group By
41

SQL Joins

1.
2.
3.
4.

Inner Join
Left Join
Right Join
Outer Join

42

SQL Constraints while creating table

1.
2.
3.
4.
5.

Primary Key
Not Null
Default Value
Auto Increment
Create Index

43

SQL Functions Examples

1.
2.
3.
4.

Count
Sum
Avg
Now

44

Linked List with Arbit pointers

45

Thank you

Ankush Singla
ankush@codingninjas.in

You might also like