1.
Which of the following type of class allows only one object of it to be created?
Correct Answer
C. Singleton class
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 called from outside the class. The class provides a static method that returns the instance of the class, and if an instance already exists, it returns that instance instead of creating a new one. This ensures that only one object of the class can exist at a time, making it a singleton class.
2.
Which of the following is not a type of constructor?
Correct Answer
B. Friend constructor
Explanation
A friend constructor is not a type of constructor. In C++, a friend function is a function that is not a member of a class but has access to the private and protected members of the class. However, constructors cannot be declared as friend functions. Therefore, a friend constructor does not exist.
3.
Which of the following is an invalid visibility label while inheriting a class?
Correct Answer
D. Friend
Explanation
Friend is an invalid visibility label while inheriting a class. In object-oriented programming, friend is not a valid access specifier for inheritance. Public, private, and protected are the three valid access specifiers used to control the visibility of class members in inheritance. Friend is used to grant access to private or protected members of a class to another class or function, but it cannot be used to specify the visibility of a derived class.
4.
Which of the following statements is correct in C++?
Correct Answer
C. Structures can have functions as members.
Explanation
The correct answer is "Structures can have functions as members." In C++, structures can have both data members and function members. This allows for the encapsulation of related data and functions within a single structure, making it a convenient way to organize and manipulate data. Unlike classes, which have default access specifiers for their members (private by default), structures have default access specifiers for their members (public by default). This means that all members of a structure are accessible by default, unless specified otherwise.
5.
Which of the following provides a reuse mechanism?
Correct Answer
B. Inheritance
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 superclass or base class. This means that the subclass or derived class can reuse and extend the functionality of the superclass, reducing code duplication and promoting code reusability. Inheritance facilitates the creation of a hierarchical relationship between classes, where subclasses can inherit and modify the attributes and methods of the superclass, promoting code organization and modularity.
6.
Which of the following cannot be used with the keyword virtual?
Correct Answer
C. Constructor
Explanation
The keyword "virtual" can be used with class, member functions, and destructor, but it cannot be used with the constructor. The reason for this is that the constructor is responsible for initializing the object and it cannot be overridden or inherited like other member functions. Therefore, it does not make sense to use the "virtual" keyword with the constructor.
7.
Which one of the following options is correct about the statement given below?The compiler checks the type of reference in the object and not the type of object.
Correct Answer
B. PolymorpHism
Explanation
Polymorphism is the correct option because it allows objects of different types to be treated as objects of a common type. In the given statement, the compiler checks the type of reference (the variable or parameter) in the object rather than the type of the actual object itself. This is a key feature of polymorphism, as it allows for flexibility and dynamic behavior in object-oriented programming.
8.
Which of the following problem causes an exception?
Correct Answer
C. A run-time error.
Explanation
A run-time error refers to an error that occurs during the execution of a program. It can be caused by various factors such as dividing by zero, accessing an invalid memory location, or attempting to perform an operation on incompatible data types. In this case, the missing semicolon or a problem in calling a function would result in a syntax error, not a run-time error. Therefore, the correct answer is A run-time error.
9.
Which of the following concepts is used to implement late binding?
Correct Answer
A. Virtual function
Explanation
Virtual functions are used to implement late binding in object-oriented programming languages. Late binding allows the selection of the appropriate function implementation at runtime based on the actual type of the object being referred to, rather than the type of the reference. This enables polymorphism, where a single function can be used to handle objects of different classes that are derived from a common base class. By declaring a function as virtual, the derived class can provide its own implementation of the function, which will be called instead of the base class implementation when the function is invoked through a base class reference or pointer.
10.
Which of the following ways are legal to access a class data member using this pointer?
Correct Answer
A. This->x
Explanation
The correct way to access a class data member using the this pointer is by using the arrow operator (->). The arrow operator is used to access the member of the object pointed to by the this pointer. In this case, the data member x is accessed using this->x. The other options, this.x, *this.x, and *this-x, are not valid ways to access a class data member using the this pointer.
11.
Which of the following operators cannot be overloaded?
Correct Answer
C. ?:
Explanation
The ?: operator, also known as the ternary operator, cannot be overloaded. This operator is used for conditional expressions and it takes three operands. It evaluates a condition and returns one of two values depending on whether the condition is true or false. Since the ?: operator is built into the language and has a fixed functionality, it cannot be overloaded to change its behavior.
12.
Which one of the following is the correct way to declare a pure virtual function?
Correct Answer
D. Virtual void Display(void) = 0;
Explanation
The correct way to declare a pure virtual function is by using the syntax "virtual void Display(void) = 0;". The keyword "virtual" indicates that the function is virtual, and the "= 0" at the end indicates that the function is pure virtual. A pure virtual function is a virtual function that has no implementation in the base class and must be overridden in the derived classes.
13.
Which of the following correctly describes overloading of functions?
Correct Answer
C. Ad-hoc polymorpHism
Explanation
Ad-hoc polymorphism is the correct term to describe the overloading of functions. This refers to the ability of a function to perform different operations based on the type or number of arguments passed to it. It allows multiple functions with the same name but different parameter lists to coexist and be called based on the specific arguments provided. This allows for flexibility and code reusability by providing different implementations of a function for different data types or argument combinations.
14.
Which of the following approach is adapted by C++?
Correct Answer
C. Bottom-up
Explanation
C++ follows the bottom-up approach. This means that the program starts executing from the lowest level of the hierarchy and gradually moves up to the higher levels. In C++, functions are defined before they are used, allowing the program to be organized in a way that functions can call each other in a hierarchical manner. This approach helps in efficient memory management and allows for better code organization and reusability.
15.
Which of the following keyword is used to overload an operator?
Correct Answer
A. Operator
Explanation
The keyword "operator" is used to overload an operator in C++. Overloading an operator allows us to redefine the behavior of an operator for user-defined types. This means we can use operators like +, -, *, /, etc. with our own custom classes or data types. By overloading an operator, we can define what it means to add, subtract, multiply, or divide objects of our own class.
16.
Which inheritance type is used in the class given below? class A : public X, public Y {}
Correct Answer
B. Multiple inheritance
Explanation
The class A is inheriting from two different classes, X and Y, using the public access specifier. This means that class A will have access to both the public and protected members of classes X and Y. This is an example of multiple inheritance, where a class can inherit from multiple base classes.
17.
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 templates, where different functions or templates can be called based on the types of arguments passed. Runtime polymorphism is achieved through inheritance and virtual functions, where a base class pointer can point to objects of different derived classes, and the appropriate function is called based on the actual object type at runtime.
18.
Destructor has the same name as the constructor and it is preceded by ______ .
Correct Answer
C. ~
Explanation
The destructor has the same name as the constructor and is preceded by the tilde (~) symbol. This symbol is used to indicate that the function is a destructor.
19.
If the copy constructor receives its arguments by value, the copy constructor would
Correct Answer
C. Call itself recursively
Explanation
If the copy constructor receives its arguments by value, it means that the copy constructor is being called with a copy of an object as its argument. In this case, if the copy constructor calls itself recursively, it would create an infinite loop where the copy constructor keeps calling itself with copies of the object. This would lead to a stack overflow error and the program would crash. Therefore, the correct answer is that the copy constructor would call itself recursively.
20.
Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?
Correct Answer
C. Compiler
Explanation
The compiler implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class. A default constructor is a constructor with no parameters, and it is automatically generated by the compiler if no other constructors are defined. This default constructor initializes the member variables of the class with their default values.
21.
Which of the following never requires any arguments?
Correct Answer
D. Default constructor
Explanation
A default constructor is a special type of member function that is automatically called when an object of a class is created without any arguments. It is used to initialize the object's data members to their default values. Unlike other types of functions, a default constructor does not require any arguments to be passed to it. Therefore, it never requires any arguments.
22.
To ensure that every object in the array receives a destructor call, always delete memory allocated as an array with operator __________ .
Correct Answer
A. Delete[ ]
Explanation
To ensure that every object in the array receives a destructor call, it is necessary to use the "delete[]" operator. This operator is specifically designed to deallocate memory that was allocated using the "new[]" operator for arrays. Using the "delete" operator without the square brackets would only deallocate memory for a single object, not an array of objects. Similarly, "kill[]" and "free[]" are not valid operators in C++ for deallocating memory. Therefore, the correct operator to use in this case is "delete[]".
23.
Which of the following function prototype is perfectly acceptable?
Correct Answer
A. Int Function(int Tmp = Show());
Explanation
The correct answer is "int Function(int Tmp = Show());" because it is a valid function prototype. It declares a function named "Function" that takes an integer parameter "Tmp" with a default value set to the result of the function "Show()". This means that if no argument is provided when calling the "Function" function, it will use the default value returned by "Show()".
24.
Which of the following statement will be correct if the function has three arguments passed to it?
Correct Answer
A. The trailing argument will be the default argument.
Explanation
If a function has three arguments passed to it, the trailing argument will be the default argument. This means that the first two arguments will be explicitly passed by the caller, while the third argument will take on its default value as defined in the function's declaration.
25.
Which of the following statement is correct?
Correct Answer
C. All the parameters of a function can be default parameters.
Explanation
In Python, all the parameters of a function can be default parameters. Default parameters allow us to assign a default value to a parameter, which is used when the argument for that parameter is not provided. This means that if no arguments are passed for any of the parameters, the default values will be used. Having all parameters as default parameters gives us flexibility in calling the function with any combination of arguments, as any missing arguments will use their default values.
26.
Where the default value of parameter have to be specified?
Correct Answer
A. Function prototype
Explanation
The default value of a parameter has to be specified in the function prototype. The function prototype is a declaration of the function that includes the function name, return type, and parameter types. It allows the compiler to know about the function before it is defined or called. By specifying the default value in the function prototype, the compiler knows what value to use for the parameter if no argument is provided during the function call.
27.
Which of the following function / types of function cannot have default parameters?
Correct Answer
B. Main()
Explanation
Main() function cannot have default parameters because it is the entry point of a program and it must follow a specific signature defined by the programming language. The main() function is called by the operating system to start the execution of a program, and it expects a specific set of arguments (argc and argv) to be passed to it. Therefore, it cannot have default parameters as it would conflict with the expected signature.
28.
Functions can be declared to return a reference type. There are reasons to make such a declaration/Which of the following reasons are correct?- The information being returned is a large enough object that returning a reference is more efficient than returning a copy.
- The type of the function must be a R-value.
Correct Answer
C. Both 1 and 2 are correct.
Explanation
Both 1 and 2 are correct. Functions can be declared to return a reference type when the information being returned is a large enough object that returning a reference is more efficient than returning a copy. Additionally, the type of the function can be an R-value.
29.
A reference is declared using the _____ symbol.
Correct Answer
B. &
Explanation
The correct answer is "&". In programming, the "&" symbol is used to declare a reference variable. A reference variable is a type of variable that refers to an existing object in memory rather than holding its own value. By using the "&" symbol, a reference variable can be declared and assigned to an existing object, allowing multiple variables to refer to the same object.
30.
Reference is like a _____.
Correct Answer
B. Pointer
Explanation
A pointer is a reference to a memory address that allows us to directly access and manipulate the data stored at that address. Similarly, a reference in programming is a type that refers to another type, allowing us to access and manipulate the data of the referenced type. Therefore, a pointer can be considered as a reference, making it the most suitable option for completing the analogy in the question.
31.
Which stream class is to only write on files ?
Correct Answer
A. Ofstream
Explanation
ofstream is the correct answer because it is a stream class in C++ that is used specifically for writing data to files. It is derived from the ostream class and provides functions and operators to write data to output files. ifstream, on the other hand, is used for reading data from input files, fstream is used for both reading and writing, and iostream is a base class for both input and output streams but does not specifically cater to file operations.
32.
Which among following is used to open a file in binary mode ?
Correct Answer
D. Ios::binary
Explanation
The correct answer is ios::binary. This is because ios::binary is used to open a file in binary mode. Binary mode is used when dealing with non-text files, such as image or audio files, where the data is represented in binary format instead of characters.
33.
Which is correct syntax ?
Correct Answer
B. Myfile.open ("example.bin", ios::out);
Explanation
The correct syntax is myfile.open ("example.bin", ios::out); because it uses the correct syntax for opening a file with the specified filename and mode. The ios::out flag is used to open the file in output mode, allowing writing to the file.
34.
How to get position to the nth byte of fileObject ?
Correct Answer
B. FileObject.seekg( n );
Explanation
The correct answer is fileObject.seekg( n ). This is because the seekg() function is used to set the position of the next character to be extracted from the input stream associated with the fileObject. It takes the offset value n as its argument and sets the position to the nth byte in the file. The other options provided in the question are incorrect syntax or use incorrect arguments for the seekg() function.
35.
What is meant by multiple inheritance?
Correct Answer
C. Deriving a derived class from more than one base class
Explanation
Multiple inheritance refers to the concept of deriving a derived class from more than one base class. In this scenario, the derived class inherits the properties and behaviors of multiple base classes, allowing it to access and use the features of each base class. This allows for greater flexibility in designing and implementing class hierarchies, as it enables the derived class to combine the characteristics of multiple base classes.
36.
Which symbol is used to create multiple inheritance?
Correct Answer
B. Comma
Explanation
Comma is used to create multiple inheritance in some programming languages, such as C++. Multiple inheritance allows a class to inherit from more than one base class, and the comma is used to separate the names of the base classes in the class declaration. This allows the derived class to inherit the properties and behaviors from multiple parent classes.
37.
Which of the following advantages we lose by using multiple inheritance?
Correct Answer
C. Both of the above
Explanation
When using multiple inheritance, we lose the advantage of dynamic binding and polymorphism. Dynamic binding allows the selection of the appropriate function at runtime based on the object type, while polymorphism allows objects of different classes to be treated as objects of a common superclass. However, with multiple inheritance, conflicts may arise when two base classes have the same function name, leading to ambiguity and making it difficult to determine which function should be called. This results in the loss of dynamic binding and polymorphism advantages.
38.
Which design patterns benefit from the multiple inheritance?
Correct Answer
A. Adapter and observer pattern
Explanation
The adapter and observer patterns benefit from multiple inheritance because they involve the need to inherit from multiple classes or interfaces. The adapter pattern allows objects with incompatible interfaces to work together by adapting one interface to another, and multiple inheritance can be used to inherit from both the target interface and the adapting class. The observer pattern involves a one-to-many relationship between objects, where multiple inheritance can be used to inherit from both the subject being observed and the observer interface. Therefore, these patterns can benefit from multiple inheritance.
39.
Which is used to describe the function using placeholder types?
Correct Answer
B. template type parameters
Explanation
Template type parameters are used to describe the function using placeholder types. These parameters allow the function to be flexible and work with different types of data without having to rewrite the function for each specific type. By using template type parameters, the function can be written once and then used with different types as needed.
40.
Pick out the correct statement.
Correct Answer
A. you only need to write one function, and it will work with many different
types.
Explanation
This statement is correct because it suggests that by writing one function, it can be used with multiple types of data. This promotes code reusability and reduces the need for duplicating code for different data types.
41.
What is data hiding ?
Correct Answer
A. It is related with hiding internal object details
Explanation
Data hiding is a concept in object-oriented programming that involves encapsulating the internal details of an object and preventing direct access to them from outside the object. This is done to ensure that the internal state and implementation of an object are not exposed to the external world, promoting security, modularity, and flexibility in software development. By hiding the internal details, the object can control how it is accessed and manipulated, providing a level of abstraction and protecting its integrity.
42.
What is class in c++ ?
Correct Answer
A. When you define a class, you define a blueprint for a data type.
Explanation
A class in C++ is a blueprint for creating objects of a particular data type. It defines the structure and behavior of the objects that will be created based on the class. By defining a class, you specify the attributes (data members) and methods (member functions) that the objects of that class will have. This allows you to create multiple objects of the same class, each with its own set of attributes and behavior. The class acts as a template or blueprint that can be used to create objects with similar characteristics.
43.
What is object in C++ ?
Correct Answer
C. Object is an instance of a class.
Explanation
In C++, an object is an instance of a class. A class is a blueprint or template that defines the properties and behaviors of objects. When we create an object, we are essentially creating a specific instance of that class, with its own unique set of values for the member variables. This allows us to create multiple objects of the same class, each with its own distinct characteristics and behaviors.
44.
What is purpose of abstract class ?
Correct Answer
D. To provide an appropriate base class from which other classes can inherit.
Explanation
An abstract class is designed to serve as a blueprint or template for other classes to inherit from. It cannot be instantiated on its own but provides a common structure and behavior that can be shared by its subclasses. This allows for code reusability and promotes a hierarchical organization of classes. It also enforces the implementation of certain methods or properties in its subclasses, ensuring that they adhere to a specific contract. Therefore, the purpose of an abstract class is to provide an appropriate base class from which other classes can inherit.
45.
What is default visibility mode for members of classes in C++ ?
Correct Answer
A. Private
Explanation
In C++, the default visibility mode for members of classes is private. This means that by default, the members of a class are only accessible within the class itself and cannot be accessed from outside the class. Private members can only be accessed through public member functions or friend functions.
46.
Which one do you like?
Correct Answer
A. Option 1
47.
Which among following is not a valid visibility mode in c++ program ?
Correct Answer
D. Limited
Explanation
The visibility modes in C++ determine the accessibility of class members. Private members can only be accessed within the class, public members can be accessed from anywhere, and protected members can be accessed within the class and its derived classes. However, "Limited" is not a valid visibility mode in C++.
48.
Which one do you like?
Correct Answer
A. Option 1
Explanation
The given question asks for personal preference, so the correct answer would depend on the individual's liking. Since the answer provided is "Option 1," it implies that the person prefers the first option among the given choices.
49.
How we can define member function outside the class ?
Correct Answer
D. Using scope resolution
Explanation
Member functions in C++ can be defined outside the class by using the scope resolution operator (::). This allows the member function to be defined separately from the class declaration, providing better organization and readability of the code. By using the scope resolution operator, the function can be associated with the class and accessed using the class name followed by the scope resolution operator. This method is commonly used when the function implementation is lengthy or when the class has multiple member functions.
50.
Which among following is correct way of declaring object of a class ?
Correct Answer
A. Classname Objectname;
Explanation
The correct way of declaring an object of a class is by using the syntax "Classname Objectname;". This syntax creates an instance of the class with the specified name. The other options provided in the question are incorrect syntax for declaring objects in C++.