6 Virtual Function Polymorphism And Miscellaneous C Features

Object Oriented Programming · Unit 6 · 5 hrs

Virtual Function, Polymorphism, and miscellaneous C++ Features

Exam-focused notes for Virtual Function, Polymorphism, and miscellaneous C++ Features (Object Oriented Programming, CSC166): what the TU syllabus asks and how it has actually been tested, with 10 solved past questions from this unit.

What this unit covers

  • Concept of Virtual functions
  • Late Binding
  • Abstract class and pure virtual functions
  • Virtual Destructors
  • Virtual base class
  • Friend function and Static function
  • Assignment and copy initialization
  • Copy constructor
  • This pointer
  • Concrete classes
  • Polymorphism and its roles

Friend function and Static function

20805 marks

Explain about friend function and friend class with an example. [5]

A friend function is a function that is not a member of a class but has access to the private and protected members of that class. - The declaration is placed inside the class body (in either private or public section) preceded by the keyword friend - It is...

Full solved answer →
20795 marks

Write short note on: a) Friend Function b) Early binding and late binding [5]

--- A friend function in C++ is a function that is not a member of a class but has the privilege to access the private and protected members of that class. It is declared inside the class using the keyword friend. - It is declared inside the class but defin...

Full solved answer →
20785 marks

What is the concept of friend function? How it violates the data hiding principle? Justify with example. [5]

A friend function is a non-member function that is granted special access to the private and protected members of a class. Although it is not a member of the class, it can access all private and protected data of that class as if it were a member. The decla...

Full solved answer →

Concept of Virtual functions

20805 marks

What is the use of reinterpret cast operator? Why do we need virtual function? [5]

--- reinterpretcast is a cast operator in C++ that converts one pointer type to another pointer type, even if the types are unrelated. It forces the compiler to treat the bit pattern of one type as if it were another type entirely. As noted in the reference...

Full solved answer →
20805 marks

Explain the reason for member function overriding when using virtual function. [5]

Overriding means defining a member function with the same name in both the base class and the derived class. When such a function exists in both classes, the derived class function overrides the base class function. Virtual function is a member function in ...

Full solved answer →

Abstract class and pure virtual functions

20805 marks

Differentiate between concrete class and abstract class. Define class template and function template with syntax. [5]

--- As stated in the notes: "There are two main types of classes: Abstract class and Concrete class. The main difference between the two arises from the level of implementation of their method functionalities." Feature Concrete Class Abstract Class --------...

Full solved answer →

Polymorphism and its roles

207610 marks

Explain types of polymorphism briefly. Write down roles of polymorphism. How can we achieve dynamic polymorphism briefly? Write down roles of polymorphism. How can we achieve dynamic polymorphism? Explain with example.[10]

Polymorphism means "one name, many forms." It allows the same function or operator to behave differently depending on the context. There are two main types: --- - The function to be called is determined at compile time. - Also called static binding or early...

Full solved answer →
2080.15 marks

Difference between compile time and run time polymorphism. [5]

Polymorphism means that the same thing or name exists in many forms to perform various actions. In C++, it is classified into two types: --- - Achieved using function overloading and operator overloading. - The compiler directly associates an address to the...

Full solved answer →

This pointer

20765 marks

What is this pointer? How can we use it for name conflict resolution? Illustrate the use of multiple catch statement with example. [5]

--- The this pointer is an implicit (hidden) pointer available inside every non-static member function of a class. It automatically points to the object that invoked the member function. - Every object has access to its own address through the this pointer....

Full solved answer →
2080.15 marks

Write short notes on: a. This pointer b. ios member function [5]

--- In C++, this is a special implicit pointer that is automatically passed to every non-static member function of a class. It holds the address of the object that invokes the member function. - When a member function is called on an object, the compiler se...

Full solved answer →