C++ Programming Question and Answers

6. What are virtual functions?
 
  • Virtual functions are used with inheritance, they are called according to the type of object pointed or referred, not according to the type of pointer or reference.
  • In other words, virtual functions are resolved late, at runtime. Virtual keyword is used to make a function virtual.
  • C++ program with runtime polymorphism (use of virtual functions).
  • A base class and a derived class.
  • A function with same name in base class and derived class.
  • A pointer or reference of base class type pointing or referring to an object of derived class.
 
Your Name Your Email-ID
Your Answer
7. What is function overloading and operator overloading?
  Function overloading:
  • C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order to the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.
Operator overloading:
  • allows existing C++ operators to be preferred so that they work on objects of user defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant façade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).
 
Your Name Your Email-ID
Your Answer
8. Differentiate between a template class and class template?
  Template class:
  • A generic definition or a parameterized class not instantiated until the client provides the needed information. It's jargon for plain templates.
Class template:
  • A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It's jargon for plain classes.
 
Your Name Your Email-ID
Your Answer
9. What is the difference between method overloading and method overriding?
 
  • Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters).
  • Method overriding is the ability of the inherited class rewriting the virtual method of the base class.
 
Your Name Your Email-ID
Your Answer
10. What is friend function?
 
  • As the name suggests, the function acts as a friend to a class.
  • As a friend of a class, it can access its private and protected members.
  • A friend function is not a member of the class. But it must be listed in the class definition.
 
Your Name Your Email-ID
Your Answer
123456789101112


131415 Page 2 of 15