Functions and OOP Features - user-defined functions, parameter passing, virtual functions, constructors, destructors, overloading, templates - Question Bank
1. What is the primary goal of encapsulation in OOP?
2. A template function is defined using which keyword prefix?
3. Which of the following is a key benefit of using virtual functions?
4. If a base class has a virtual destructor, what is the implication for derived class objects?
5. What does a constructor achieve that a regular function cannot regarding object initialization?
6. Consider a function `void display(int a, int b)`. If you create another function `void display(double x, double y)`, this is an example of:
7. Which OOP feature allows an object to take on many forms?
8. A function template can be specialized for a specific data type. This means:
9. What is the scope resolution operator (`::`) used for?
10. When is it generally recommended to use pass by reference rather than pass by pointer?
11. What is the purpose of the `this` pointer in C++?
12. In the context of virtual functions, what is an abstract class?
13. If a function is declared as `void func(int *ptr)`, the parameter `ptr` is passed by:
14. What is the primary benefit of using templates?
15. Which concept allows a single operator symbol (like `+` or `-`) to perform different operations based on the operands it is applied to?
16. A destructor can be overloaded.
17. What happens if a class has multiple constructors?
18. A virtual function in a base class allows derived classes to provide their own specific implementation, which is known as:
19. Which of the following is NOT a common reason to use user-defined functions?
20. In C++, `std::vector<int>` is an example of using:
21. What is the purpose of the `typename` keyword when declaring a template parameter for a dependent type?
22. What is the main difference between function overloading and function overriding?
23. If a class has a destructor, when is it guaranteed to be called?
24. What is the term for a constructor that can be called with a single argument?
25. A derived class can access public and protected members of its base class. What is the purpose of `protected` access specifier?
26. Pass by pointer is similar to pass by reference in that:
27. When using templates, the compiler generates actual code for each specific data type used. This process is known as:
28. Which of the following is an example of compile-time polymorphism?
29. What does `~` signify when used before a class name in C++?
30. A copy constructor is called when:
31. A pure virtual function is a virtual function that:
32. What is the primary advantage of pass by reference over pass by value for large objects?
33. A class template allows you to define:
34. Which of the following is NOT a valid way to achieve function overloading?
35. When does a constructor typically get called?
36. What is the keyword used in C++ to declare a virtual function?
37. If a function parameter is declared as `int& var`, it means the parameter is passed by:
38. A function template in C++ is used to create:
39. Operator overloading is a form of:
40. What is the syntax for a destructor in C++?
41. A constructor that takes no arguments or has default values for all its arguments is known as a:
42. Consider a base class `Animal` and a derived class `Dog`. If `speak()` is a virtual function in `Animal` and is overridden in `Dog`, calling `speak()` on a `Dog` object through a pointer to `Animal` will invoke:
43. When a variable is passed by value to a function, any changes made to the parameter inside the function:
44. What is the purpose of a template in C++?
45. Function overloading allows multiple functions with the same name to exist if they differ in:
46. Which member function is automatically called when an object of a class is destroyed?
47. What is the main role of a constructor in object-oriented programming?
48. In C++, what is a virtual function primarily used for?
49. Which parameter passing mechanism allows a function to modify the original variable passed to it?
50. What is the primary purpose of a user-defined function in programming?