1.
Which of the following concepts provides facility of using object of one class inside another class?
Correct Answer
C. Composition
Explanation
Composition is a concept in object-oriented programming that allows for the use of objects of one class inside another class. This means that one class can contain an instance of another class as a member variable. This allows for a strong relationship between the two classes, where the inner class is an essential part of the outer class. This concept promotes code reusability and modular design by allowing objects to be composed of other objects.
2.
cout is a/an __________ .
Correct Answer
D. Object
Explanation
The correct answer is "object" because "cout" is an object in C++. It is an instance of the "ostream" class and is used to display output on the console.
3.
Which of the following is not a type of constructor?
Correct Answer
C. Friend constructor
Explanation
A friend constructor is not a type of constructor. In object-oriented programming, a constructor is a special method that is used to initialize objects of a class. It is called automatically when an object is created. The copy constructor creates a new object by copying the values of an existing object. The default constructor is a constructor that takes no arguments. The parameterized constructor is a constructor that takes one or more parameters. However, a friend constructor is not a recognized type of constructor.
4.
Which of the following type of class allows only one object of it to be created?
Correct Answer
C. Singleton
Explanation
A Singleton class allows only one object of it to be created. This is achieved by making the constructor of the class private, so that it cannot be accessed from outside the class. The class itself provides a static method that returns the instance of the class, and this method ensures that only one instance is created and returned. This pattern is commonly used in scenarios where there should be only one instance of a class, such as a database connection or a logger.
5.
Which of the following concepts means determining at runtime what method to invoke?
Correct Answer
B. Dynamic binding
Explanation
Dynamic binding refers to the process of determining at runtime which method to invoke based on the actual type of the object. This allows for polymorphism, where different objects of different classes can be treated as objects of a common superclass and their specific methods can be called based on their actual types. Dynamic binding is an important concept in object-oriented programming as it enables flexibility and extensibility in the code.
6.
How "Late binding" is implemented in C++?
Correct Answer
B. Using virtual tables
Explanation
Late binding in C++ is implemented using virtual tables. A virtual table, also known as a vtable, is a lookup table of function pointers used to implement dynamic dispatch. When a class has virtual functions, a vtable is created for that class, which contains pointers to the virtual functions. During runtime, when a virtual function is called through a base class pointer, the vtable is used to determine the correct function to be called based on the actual object type. This allows for the implementation of polymorphism and enables late binding, where the function to be called is determined at runtime.
7.
Which of the following operator is overloaded for object cout?
Correct Answer
A. <<
Explanation
The
8.
Which of the following is the correct way of declaring a function as constant?
Correct Answer
C. Int ShowData(void) const { /* statements */ }
Explanation
The correct way of declaring a function as constant is by using the "const" keyword after the closing parenthesis of the function declaration. This ensures that the function does not modify any member variables of the class in which it is defined. In this case, the correct answer is "int ShowData(void) const { /* statements */ }".
9.
Which of the following ways are legal to access a class data member using this pointer?
Correct Answer
A. This->x
Explanation
The correct answer is "this->x". In C++, the "this" pointer is a special pointer that points to the object itself. By using the "->" operator, we can access the data member "x" of the current object. The "->" operator is used to access members of an object through a pointer. Therefore, "this->x" is the correct way to access a class data member using the "this" pointer.
10.
Which of the following is correct about the statements given below?
- All operators can be overloaded in C++.
- We can change the basic meaning of an operator in C++.
Correct Answer
D. Both are false
Explanation
In C++, not all operators can be overloaded. Some operators, such as the dot operator (.), the scope resolution operator (::), the ternary operator (?:), and the sizeof operator, cannot be overloaded. Therefore, statement 1 is false. Additionally, while operator overloading allows us to change the behavior of an operator, it does not change its basic meaning. The basic meaning of an operator remains the same, but we can define new behavior for the operator when it is used with user-defined types. Therefore, statement 2 is also false.
11.
Which of the following are available only in the class hierarchy chain?
Correct Answer
C. Protected Data members
Explanation
Protected data members are available only in the class hierarchy chain. This means that they can be accessed by the class in which they are defined, as well as by any derived classes. Protected data members are not accessible by objects of the class or by functions outside the class hierarchy chain. This access level provides a balance between the strict encapsulation of private data members and the complete accessibility of public data members.
12.
Which of the following is not a type of inheritance?
Correct Answer
C. Distributive
Explanation
Distributive inheritance is not a recognized type of inheritance in object-oriented programming. The other options listed - multiple, multilevel, and hierarchical - are all valid types of inheritance. Multiple inheritance refers to a class inheriting from multiple parent classes, multilevel inheritance refers to a class inheriting from a derived class, and hierarchical inheritance refers to a class inheriting from a single parent class. However, distributive inheritance is not a commonly used or recognized term in the context of inheritance.
13.
What happens if the base and derived class contains definition of a function with same prototype?
Correct Answer
D. Base class object will call base class function and derived class object will call derived class function.
Explanation
When both the base and derived classes contain a function with the same prototype, the function in the derived class overrides the function in the base class. This means that when a base class object calls the function, it will call the base class function, and when a derived class object calls the function, it will call the derived class function. This is known as function overriding.
14.
Which of the following statements is correct in C++?
Correct Answer
B. Structures can have functions as members.
Explanation
In C++, structures can have functions as members. This is a key difference between structures and classes in C++. While both structures and classes can have data members, only structures can have functions as members. This allows for more flexibility in organizing and defining data and functions within a structure.
15.
Which of the following access specifier is used as a default in a class definition?
Correct Answer
C. Private
Explanation
In a class definition, the access specifier that is used as a default is "private". This means that the members of the class, such as variables and methods, can only be accessed within the class itself and not from outside the class or its subclasses. It provides the highest level of encapsulation and data hiding, ensuring that the internal implementation details of the class are not exposed to other parts of the program.
16.
What is correct about the static data member of a class?
Correct Answer
D. A static member function can access only static data members of a class and A static data member is shared among all the object of the class.
Explanation
A static member function can access only static data members of a class because static member functions do not have access to the non-static members of a class. A static data member is shared among all the objects of the class, meaning that any changes made to the static data member will be reflected in all instances of the class. This allows for the sharing of data between different objects of the same class.
17.
Which of the following provides a reuse mechanism?
Correct Answer
B. Inheritence
Explanation
Inheritance provides a reuse mechanism in object-oriented programming. It allows a class to inherit properties and behaviors from another class, known as the parent or base class. This enables the derived class to reuse the code and functionality of the base class, reducing code duplication and promoting code reusability. Inheritance also supports the concept of polymorphism, where objects of derived classes can be treated as objects of the base class, providing flexibility and extensibility in the design of software systems.
18.
Which of the following statement is correct?
Correct Answer
B. Object is an instance of a class.
Explanation
The correct answer is "Object is an instance of a class." In object-oriented programming, a class is a blueprint for creating objects. An object is an instance of a class, meaning it is created based on the definition provided by the class. Each object created from a class has its own set of properties and behaviors defined by the class. Therefore, an object is an instance of a class.
19.
How many types of polymorphisms are supported by C++?
Correct Answer
B. 2
Explanation
C++ supports two types of polymorphisms: compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved through function overloading and template specialization, where different functions or templates with the same name but different parameters or template arguments are used. Runtime polymorphism is achieved through virtual functions and inheritance, where a base class pointer can point to objects of different derived classes, allowing for dynamic dispatch of function calls based on the actual type of the object being referred to.
20.
Which of the following is an abstract data type?
Correct Answer
B. Class
Explanation
An abstract data type is a data type that is defined by the behavior it exhibits rather than the specific implementation details. It provides a set of operations that can be performed on the data without revealing the internal representation. A class in programming languages like Java or C++ is an example of an abstract data type because it encapsulates data and functions/methods that operate on that data, providing a way to create objects and manipulate them.