oops advanced

50
 OOPs – Advanced

Post on 19-Oct-2014

323 views

Category:

Education


0 download

DESCRIPTION

Last lecture on OOPS

TRANSCRIPT

Page 1: OOPS Advanced

   

OOPs – Advanced

Page 2: OOPS Advanced

   

OOPs – Const Dest

● Constructor : Things to do when a new object is created

● Destructor : Things to do when object's life ends. 

Page 3: OOPS Advanced

   

OOPs – Const Dest

Page 4: OOPS Advanced

   

OOPs – More Constructors

Page 5: OOPS Advanced

   

OOPs – More Constructors : ERRATA

Page 6: OOPS Advanced

   

Lets answer the TRICK Question

Page 7: OOPS Advanced

   

Lets do the TRICK Question

15 years back, before C++ came in,

Address(cool) = Address(coolness)

COMPILER OPTIMIZATION!

Page 8: OOPS Advanced

   

Lets answer the TRICK Question

● While making a COPY of the parameter, the Copy­constructor of the parameter should be called!

● Thus the compiler optimization was invalid.

Page 9: OOPS Advanced

   

OOPs – Interfaces

● Class definition, no logic● Defines what functions and data (vars) 

should be present in the Class that IMPLEMENTS an interface.

Page 10: OOPS Advanced

   

OOPs – Interfaces

Page 11: OOPS Advanced

   

OOPs – Interfaces

Page 12: OOPS Advanced

   

OOPs – Abstract Class

● Small extension of Interfaces● Instead of requiring subclass to implement 

ALL virtual functions, it also defines some function's body.

Page 13: OOPS Advanced

   

OOPs – Abstract Class

Page 14: OOPS Advanced

   

OOPs – Virtual keyword

OUTPUT for each?

Page 15: OOPS Advanced

   

OOPs – Virtual keyword

Page 16: OOPS Advanced

   

OOPs – Static Variables

Page 17: OOPS Advanced

   

OOPs – Static Variables

Page 18: OOPS Advanced

   

OOPs – Inline functions

Page 19: OOPS Advanced

   

OOPs – Friend Function

PS: Never encountered a good use for a friend function  :­/

Page 20: OOPS Advanced

   

OOPs – Static Var and Function

Output?

Page 21: OOPS Advanced

   

OOPs – Static Var and Function

Page 22: OOPS Advanced

   

OOPs – Namespace

Page 23: OOPS Advanced

   

OOPs – Namespace

Page 24: OOPS Advanced

   

OOPs – Namespace

Page 25: OOPS Advanced

   

OOPs – Namespace

Page 26: OOPS Advanced

   

OOPs – Shallow Copy

Output?

Page 27: OOPS Advanced

   

OOPs – Shallow Copy

Page 28: OOPS Advanced

   

OOPs – Deep Copy

Output?

Page 29: OOPS Advanced

   

OOPs – Deep Copy

Page 30: OOPS Advanced

   

Inheritance ­ advanced

● Types of inheritance :● Public ● Private ● Protected

Page 31: OOPS Advanced

   

Inheritance ­ advanced

● Types of inheritance :● Public ● Private ● Protected

Page 32: OOPS Advanced

   

Inheritance ­ advanced

● Types of inheritance :● Public ● Private ● Protected

Page 33: OOPS Advanced

   

CLASS DIAGRAM

READUP : UML Elements

Page 34: OOPS Advanced

   

QUESTIONS

Page 35: OOPS Advanced

   

Q) Variables

● What is the size of a NULL value in C++?

Page 36: OOPS Advanced

   

Q) Variables

● What is the size of a NULL value in C++?● 1 Byte

Page 37: OOPS Advanced

   

Q) Functions

● Python uses which of the following?● Call by value● Call by reference● Both, interchangeably● None of the above

Page 38: OOPS Advanced

   

Q) Functions

● Python uses which of the following?● Call by value● Call by reference● Both, interchangeably● None of the above : It uses Call­by­object

Page 39: OOPS Advanced

   

Q) C'tors and d'tors

OUTPUT?

Page 40: OOPS Advanced

   

Q) C'tors and d'tors

Page 41: OOPS Advanced

   

Q) This pointer

What is the error here?

Page 42: OOPS Advanced

   

Q) What are the OOPs conepts used here?

Page 43: OOPS Advanced

   

Q) Inheritance

WHAT VARIABLES ARE ACCESSIBLETO

Function foo() ?

Page 44: OOPS Advanced

   

Q) Inheritance

WHAT VARIABLES ARE ACCESSIBLETO

Function foo() ?

a_v1, a_v2, b_v2, b_v3, c_v2, c_v3

WHAT VARIABLES ARE ACCESSIBLETO

Object d?

Page 45: OOPS Advanced

   

Q) Inheritance

WHAT VARIABLES ARE ACCESSIBLETO

Function foo() ?

a_v1, a_v2, b_v2, b_v3, c_v2, c_v3

WHAT VARIABLES ARE ACCESSIBLETO

Object d?a_v2, c_v3

Page 46: OOPS Advanced

   

Q) This pointer

What is the error here?

Page 47: OOPS Advanced

   

Q) Interfaces and Abs Class

● Can you instanciate an object of an Abstract class?

Page 48: OOPS Advanced

   

Q) Interfaces and Abs Class

● Can you instanciate an object of an Abstract class?● NO

Page 49: OOPS Advanced

   

Q) Interfaces and Abs Class

● Can a function be final and virtual at the same time?

Page 50: OOPS Advanced

   

Q) Interfaces and Abs Class

● Can you instanciate an object of an Abstract class?● NO

– Virtual functions HAVE to be over­ridden– Final functions CANNOT be over­ridden