MCQ with answers for (OOP) | Object Oriented Programming | 22316 [Principles of Object Oriented Programming] MSBTE
Subject | subject details |
---|---|
Program: | Diploma in Computer engineering |
Program Code | CO |
Scheme | I |
Semester | 3 |
Course: | Object Oriented Programming |
Course Code | 22316 |
Content of Chapter:-
1.1 Its need & requirement, Procedure Oriented Programming (POP) verses Object Oriented Programming(OOP)
1.3 C verses C++,structure of c++ program, simple c++ program.
1.4 Token ,keywords, variables, constants ,basic data types, user data types, type casting
operator,expression
1.5 Control structors: Decision making statements and loops.
1.6 Scope resolution operator, memory management operator.
1.7 Array ,Strings and structure in C++.
1. Who invented C++?
a) Dennis Ritchie
b) Ken Thompson
c) Brian Kernighan
d) Bjarne Stroustrup
Answer: d
Explanation: Bjarne Stroustrup is the original creator of C++ in 1979 at AT&T Bell Labs.
2. What is C++?
a) C++ is an object-oriented programming language
b) C++ is a procedural programming language
c) C++ supports both procedural and object-oriented programming language
d) C++ is a functional programming language
Answer: c
Explanation: C++ supports both procedural (step by step instruction) and object-oriented programming (using the concept of classes and objects).
3. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include [userdefined]
b) #include “userdefined”
c) #include <userdefined.h>
d) #include <userdefined>
Answer: b
Explanation: C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.
4. Which of the following is used for comments in C++?
a) /* comment */
b) // comment */
c) // comment
d) both // comment or /* comment */
Answer: d
Explanation: Both the ways are used for commenting in C++ programming. // is used for single line comments and /* … */ is used for multiple line comments.
5. Which of the following user-defined header file extension used in c++?
a) hg
b) cpp
c) h
d) hf
Answer: c
Explanation: .h extensions are used for user defined header files. To include a user defined header file one should use #include”name.h” i.e. enclosed within double quotes.
6. Which of the following is a correct identifier in C++?
a) VAR_1234
b) $var_name
c) 7VARNAME
d) 7var_name
Answer: a
Explanation: The rules for writing an identifier is as follows:
i) may contain lowercase/uppercase letters, digits or underscore (_) only
ii) should start with a non-digit character
iii) should not contain any special characters like @, $, etc.
7. Which of the following is not a type of Constructor in C++?
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Friend constructor
Answer: d
Explanation: Friend function is not a constructor whereas others are a type of constructor used for object initialization.
8. Which of the following approach is used by C++?
a) Left-right
b) Right-left
c) Bottom-up
d) Top-down
Answer: c
Explanation: C++ is an object-oriented language and OOL uses a bottom-up approach to solve/view a problem.
9. What is virtual inheritance in C++?
a) C++ technique to enhance multiple inheritance
b) C++ technique to ensure that a private member of the base class can be accessed somehow
c) C++ technique to avoid multiple inheritances of classes
d) C++ technique to avoid multiple copies of the base class into children/derived class
Answer: d
Explanation: Virtual inheritance is a C++ technique with which it ensures that a derived class contains only one copy of the base class’s variables. Refer Wikipedia for more info.
10. What happens if the following C++ statement is compiled and executed?
int *ptr = NULL;
delete ptr;
a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time
Answer: b
Explanation: The above statement is syntactically and semantically correct as C++ allows the programmer to delete a NULL pointer, therefore, the program is compiled and executed successfully.
11. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
Answer: c
Explanation: There is no operation defined for the addition of character array in C++ hence the compiler throws an error as it does not understood what to do about this expression.
12. What is the difference between delete and delete[] in C++?
a) delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case
b) delete is used to delete normal objects whereas delete[] is used to pointer objects
c) delete is a keyword whereas delete[] is an identifier
d) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects
Answer: d
Explanation: delete is used to delete a single object initiated using new keyword whereas delete[] is used to delete a group of objects initiated with the new operator.
13. What happens if the following program is executed in C and C++?
#include <stdio.h>
int main(void)
{
int new = 5;
printf("%d", new);
}
a) Error in C and successful execution in C++
b) Error in both C and C++
c) Error in C++ and successful execution in C
d) A successful run in both C and C++
Answer: c
Explanation: new is a keyword in C++, therefore, we cannot declare a variable with name new but as there is no such keyword new in C, therefore, the program is compiled and executed successfully in C.
14. What happens if the following program is executed in C and C++?
#include <stdio.h>
void func(void)
{
printf("Hello");
}
void main()
{
func();
func(2);
}
a) Outputs Hello twice in both C and C++
b) Error in C and successful execution in C++
c) Error in C++ and successful execution in C
d) Error in both C and C++
Answer: d
Explanation: As the func(void) needs no argument during its call, hence when we are calling func(2) with 2 as passed as a parameter then this statement gives the error in both C++ and C compiler.
15. Which of the following is correct about this pointer in C++?
a) this pointer is passed as a hidden argument in all static variables of a class
b) this pointer is passed as a hidden argument in all the functions of a class
c) this pointer is passed as a hidden argument in all non-static functions of a class
d) this pointer is passed as a hidden argument in all static functions of a class
Answer: c
Explanation: As static functions are a type of global function for a class so all the object shares the common instance of that static function whereas all the objects have there own instance for non-static functions and hence they are passed as a hidden argument in all the non-static members but not in static members.
29. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. char c = 74;
6. cout << c;
7. return 0;
8. }
a) I
b) J
c) A
d) N
Answer: b
Explanation: The literal value for 74 is J. So it will be printing J.
36. Which of the following symbol is used to declare the preprocessor directives in C++?
a) $
b) ^
c) #
d) *
Answer: c
Explanation: # symbol is used to declare the preprocessor directives
37. Which of the following class allows to declare only one object of it?
a) Abstract class
b) Virtual class
c) Singleton class
d) Friend class
Answer: c
Explanation: Singleton class allows the programmer to declare only one object of it, If one tries to declare more than one object the program results into error.
38. Which of the following is not a type of Constructor?
a) Friend constructor
b) Copy constructor
c) Default constructor
d) Parameterized constructor
Answer: a
Explanation: Friend function is not a constructor whereas others are a type of constructor used for object initialization.
39. Which of the following is correct?
a) Base class pointer object cannot point to a derived class object
b) Derived class pointer object cannot point to a base class object
c) A derived class cannot have pointer objects
d) A base class cannot have pointer objects
Answer: b
Explanation: C++ does not allow a derived class pointer to point a base class pointer whereas Base class can point to a derived class object. Both base class and derived class can have pointer objects.
40. Out of the following, which is not a member of the class?
a) Static function
b) Friend function
c) Constant function
d) Virtual function
Answer: b
Explanation: Friend function is not a member of the class. They are given the same.
access rights as the class member function have but they are not actual members of the class.
41. What is the other name used for functions inside a class?
a) Member variables
b) Member functions
c) Class functions
d) Class variables
Answer: b
Explanation: Functions of a class are also known as member functions of a class.
42. Which of the following cannot be a friend?
a) Function
b) Class
c) Object
d) Operator function
Answer: c
Explanation: Objects of any class cannot be made a friend of any other or same class whereas functions, classes and operator functions can be made a friend.
43. Why references are different from pointers?
a) A reference cannot be made null
b) A reference cannot be changed once initialized
c) No extra operator is needed for dereferencing of a reference
d) All of the mentioned
Answer: d
Explanation: References cannot be made null whereas a pointer can be. References cannot be changed whereas pointers can be modified.
Pointers need * operator to dereference the value present inside it whereas reference does not need an operator for dereferencing.
44. Which of the following provides a programmer with the facility of using object of a class inside other classes?
a) Inheritance
b) Composition
c) Abstraction
d) Encapsulation
Answer: b
Explanation: The concept of using objects of one class into another class is known as Composition.
45. How many types of polymorphism are there in C++?
a) 1
b) 2
c) 3
d) 4
Answer: b
Explanation: There are two types of polymorphism in C++ namely run-time and compile-time polymorphisms.
46. How run-time polymorphisms are implemented in C++?
a) Using Inheritance
b) Using Virtual functions
c) Using Templates
d) Using Inheritance and Virtual functions
Answer: d
Explanation: Run-time polymorphism is implemented using Inheritance and virtual in which object decides which function to call.
46. How compile-time polymorphisms are implemented in C++?
a) Using Inheritance
b) Using Virtual functions
c) Using Templates
d) Using Inheritance and Virtual functions
Answer: c
Explanation: Compile-time polymorphism is implemented using templates in which the types(which can be checked during compile-time) are used decides which function to be called.
47. Which of the following is an abstract data type?
a) int
b) float
c) class
d) string
Answer: c
Explanation: Class is used as an abstract data type as it can be used to give implementation independent view whereas no other data type can be used to provide this.
48. Which concept means the addition of new components to a program as it runs?
a) Data hiding
b) Dynamic binding
c) Dynamic loading
d) Dynamic typing
Answer: c
Explanation: Dynamic loading is the concept of adding new components to a program as it runs.
49. Which of the following explains the overloading of functions?
a) Virtual polymorphism
b) Transient polymorphism
c) Ad-hoc polymorphism
d) Pseudo polymorphism
Answer: c
Explanation: Ad-hoc polymorphism is a type of polymorphism in which a function denotes heterogeneous implementation depending upon the types of argument.
50. Which of the following approach is used by C++?
a) Top-down
b) Bottom-up
c) Left-right
d) Right-left
Answer: b
Explanation: C++ is an object-oriented language and OOL uses a bottom-up approach to solve/view a problem.
51. Which of the following approach is used by C++?
a) Top-down
b) Bottom-up
c) Left-right
d) Right-left
Answer: b
Explanation: C++ is an object-oriented language and OOL uses a bottom-up approach to solve/view a problem.
52. Which operator is overloaded for a cout object?
a) >>
b) <<
c) <
d) >
Answer: b
Explanation: cout in C++ uses << operator to print anything so << operator is overloaded for a cout object.
53. Which of the following cannot be used with the virtual keyword?
a) Class
b) Member functions
c) Constructors
d) Destructors
Answer: c
Explanation: Virtual keyword cannot be used with constructors as constructors are defined to initialized an object of particular class hence no other class needs constructor of other class.
54. Which concept is used to implement late binding?
a) Virtual functions
b) Operator functions
c) Constant functions
d) Static functions
Answer: a
Explanation: Virtual functions are used to implement the concept of late binding i.e. binding actual functions to their calls.
Comments
Post a Comment