Você está na página 1de 12

Quiz on Operator Overloading

1) Overloading the function operator (A) requires a class with an overloaded operator. (B) requires a class with an overloaded [ ] operator. (C) allows you to create objects that act syntactically like functions. (D) usually make use of a constructor that takes arguments. Ans: A 2) The operator that cannot be overloaded is (A) ++ (B) :: (C) ( ) (D) ~ Ans: B 3) Which of the following statements is NOT valid about operator overloading? (A) Only existing operators can be overloaded. (B) Overloaded operator must have at least one operand of its class type. (C) The overloaded operators follow the syntax rules of the original operator. (D) none of the above. Ans:D 5) Overloading a postfix increment operator by means of a member function takes (A) no argument (B) one argument (C) two arguments (D) three arguments Ans:A 6) Which of the following operator can be overloaded through friend function? (A) -> (B) = (C) ( ) (D) * Ans:D 7) Which of the following statement is valid? (A) We can create new C++ operators. (B) We can change the precedence of the C++ operators. (C) We can change the associativity of the C++ operators. (D) We can not change operator templates. Ans:D. 8) One can change the precedence of an operator when overloading it. a) True b) False Ans: b 9) When overloading operators, we can also create our own new operators. a) True b) false Ans: b 10) . Overloading without explicit arguments to an operator function called (A) Binary operator overloading (B) Unary operator overloading D (C) Class allowing access to another class ) (D) None of these Ans: b 11) Can constructors be overloaded?

a) Yes Ans: a

b)No

12) Which of the following is correct about the statements given below? 1.All operators can be overloaded in C++. 2.We can change the basic meaning of an operator in C++. (A) Only 1 is true (B) Both 1 and 2 are false................ (C) Only 2 is true (D) Both 1 and 2 are true Ans: b 13) . The Associativity of an overloaded operator, however, cannot be changed. a) True b) False Ans: a 14) Which of the following operators can be implemented as a nonmember operator? a. = (assignment operator) b. () (function call operator) c. [] (array access operator) d. + (addition operator) Ans: d 15) Which of the following is the correct prototype for an overloaded assignment operator over class Student? a) Void operator =(); b) Void operator = (Student); c) void = (Student); d) void =(const Student&); Ans: b 16) Operator Overloading is example of run time polymorphism a) True b) False Ans: b 17) . Operator overloading is (A) making C++ operators works with objects and giving new meaning to existing C++ operators (B) making C++ operators works with objects (C) giving new meaning to existing C++ operators (D) making new C++ operator Ans: B 18) In the binary overloaded operator function, second operand should be passed a) b) Excplicitly Implicitly c)passed by value d) by reference

Ans: d 19) The name of the operator function that overloads the * symbol is a) operator*() b) *operator() c) op*() d) *op() Ans: a 20) Choose the correct remarks a) C++ allows any operator to be overloaded. b) Some of the existing operators cannot be overloaded. c) Operator precedence cannot be changed. d) All the above. Ans: ( c) 21) Which of the following operators cannot be overloaded? a) The . operator b)The -> operator c) The [ ] operator. d) The & operator. Ans: a 22) Which statement about operator overloading is False? a) New operators can never be created. b) Certain overloaded operators can change the number of arguments they take. c) The precedence of an operator cannot be changed by overloading. d) Overloading cannot change how an operator works on built-in types. Ans: b 23) To implicitly overload the += operator: a) Only the = operator needs to be overloaded b) Only the + operator needs to be overloaded c) The += operator cannot be overloaded implicitly. d) Both the + and = operators need to be overloaded. Ans: c 24) The conventional way to distinguish between the overloaded pre increment and post increment operators (++) is: a) To assign a dummy value to pre increment. b) To make the argument list of post increment include an int. c) To have the post increment operator call the pre increment operator. d) Implicitly done by the compiler. Ans: b 25) It is perfectly illegal to overload the dynamic memory allocation operators: new and delete. a) True b) false Ans: b

26) All the operator function must be declared as member functions or friend functions to classes. a) True b) False Ans: a 27) Overloaded operators can have default arguments. a) True b) False Ans: b 28) Which overloaded operator cannot be inherited by derived classes. a) + b) = c) > d) * Ans: b 29) When specifying an overloaded operator for the postfix form of the increment or decrement operator, the additional argument must be of type a) float b) char c) int d) all the above Ans: c 30) To overload a member function of the base class, the name of the function and the formal parameter list of the corresponding function in the derived class must be same a) True b) False Ans: b 31) The comma operator can be overloaded. a) True b) False Ans: a 32) The overloaded operator must have at least one operand that is of user defined type. a) True b) False Ans: a 33) Which of the following operator cannot be overloaded using friend function. a) % b) << c) [ ] d) ! Ans; c 34) Compiler will report an error if a binary operator is redefined to be used as unary operator . a) True b) False Ans: a 35) Which of the following operator can be overloaded through friend function? (A) -> (B) = (C) ( ) (D) * Ans: d 36) If you overload only prefix ++ operator, the postfix ++ operator

a) does not works b) works arbitrarily c) works naturally d) works as if prefix ++ operator. Ans: d 37) The sizeof operator can be overloaded. a) True b) false Ans: b 38) When you overload << operator, the operator >> gets automatically overloaded. a) True b) False Ans: b 39) Each and every operator of c++ can be overloaded. a) True b) False Ans: b 40) You can overload unary operators to work like binary operators. a) True b) False Ans: b 41) If you do not want to overload the operator, you can achieve the same effect with user defined functions a) True b) False Ans: a 42) Operator overloading allows us to use the existing operators in new manner. a) True b) False Ans: b 43) If there were no classes, operator overloading would not be needed. a) True b) False Ans: b 44) Operator Overloading can be misused. a) True b) False Ans: a 45) If no overloaded operators are provided, c++ automatically provides them. a) True b) False Ans: b 46) If we do not use operator overloading, assuming a and b are objects of same class, the statement a+=b; is invalid. a) True b) False Ans: a 47) We cannot overload stream operators.

a) True Ans: b

b) False

48) Operator overloading is same as function overloading. a) True b) False Ans: b 49) When we overload the = operator, we want to. a) compare two objects b) compare and copy objects c) Test for equality d) assign one object to another. Ans: d 50) To overload the user input, we need to overload. operator. a)<< b)>> c)< d)> Ans: b 51) To overload user output, we need to overload..operator. a)<< b)>> c)< d)> Ans: a 52) To overload less than, we need to overload..operator. a) << b)>> c)< d)> Ans: c 53) To overload greater than, we need to overload..operator. a)<< b)>> c)< d)> Ans: d 54) If a binary operator is overloaded as a member function, how many parameters will the member function require? a) None. Both the operands are passed via object. b) One, to pass the second operand. The first operand is object itself. c) Two, to pass the first and second operands. d) Three, to pass the first and second operands, and the object on which they were called. Ans: b 55) Why is it necessary to be able to overload some operators by specifying a global function (rather than a member function)? a) Because member functions are inherited b) Because member functions are slower than global functions.

c) Because inbuilt types can't have member functions. d) Because sometimes the order of arguments puts an unmodifiable class as the first operand Ans: d 56) If both MyClass::operator+ and MyClass::operator= are overloaded, what is the effect on MyClass::operator+=? a) None. The three operators are completely independent. b) MyClass::operator+= will automatically be overloaded to call MyClass::operator+ and then MyClass::operator=. c) MyClass::operator+= will automatically be overloaded to call MyClass::operator= and then MyClass::operator+. d) MyClass::operator+= will automatically be made invalid, and the error message will suggest that the user use MyClass::operator+ and MyClass::operator= instead. Ans; a 57) Why can we say that operator overloading is a form of polymorphism? a) Because overloaded operators can be declared virtual. b) Because overloaded operators mean that code like a+b can do different things depending on the type of the objects a and b. c) Because polymorphism is the technical name for operator overloading. d) Because overloaded operators have many (poly) shapes (morphus). Ans: b 58) Why is operator overloading sometimes desirable a) To change the precedence of inbuilt operators for user-defined classes. b) To make user-defined classes act more like inbuilt classes (i.e. to make them more intuitive to use. c) All of the above d) None of the above. Ans: d 59) The term overloaded refers to A. an error where more than one method matches a method call B. two or more methods in the same class that have the same name C. method calls where there are two many actual parameters D. two or more methods in different classes that have the same name Ans: b 60) The operator << when overloaded in a class (A) must be a member function (B) must be a non member function (C) can be both (A) & (B) above (D) cannot be overloaded Ans:c

61) It is good programming practice to use binary operator as binary operator and unary operator as unary operator. a) True b) False Ans: a 62) Complier will generate error if binary operators are treated as unary operators. a) True b) False Ans: a 63) With operator overloading debugging becomes easier. a)True b) False Ans: a 64) Operator overloading helps to gain greater control over behavior of objects in the program. a)True b)False Ans: a 65) When operator function returns an object of the class it operates on, the return type is name of the class. a) True b) False Ans:a 66) The complier distinguishes an operator function from ordinary member function of the class by the keyword a) Class b) Operator c) Struct d) Double. (b) Ans: b 67) Which of the following is valid declaration of overloaded operator function a) complex operator +(complex); b) int operator > (distance). c) string operator == (string). d) all the above. Ans: d 68)The operations predefined for primitive data types are not automatically transferred to user defined types. a) True b) False Ans:a

Quiz on Type Conversion


69) To convert from a user defined class to a basic type, you would most likely use. (A) A built-in conversion function. (B) A one-argument constructor. (C) A conversion function thats a member of the class. (D) An overloaded = operator. Ans:C

70) During class type to class type conversion ,if the conversion facility is to be included in the source class, then A ) A) A constructor for conversion is required in source class. B) A constructor for conversion is required in the destination class. C ) C) Operator function is required in the source class. D) Operator function is required in the destination class. Ans: c 71) The prototypes of overloaded cast operator functions do not: a) Specify the type they convert to. b) Need to be defined inside the class whose objects are being converted. c) Specify the type that is being converted. d)Specify a return type. Ans: d 72)For converting int values to an object of class MyNumber a) Constructor with an int parameter must be defined in the class MyNumber. b) The conversion function: operator int() must be defined in the class MyNumber. c) Both of the above are required to be defined in the class MyNumber. d) None of the above is required to be defined in class MyNumber. Some independent non member function must perform the conversion Ans: a 73) Conversion or typecasting operator function have.arguments and return type. a) one; one b) one;no c) no;one d) no;no Ans: d 74) As typecast operator does not allow explicit mention of return type, you must not use the return statement in the body of the respective typecast operator function. a) True b) False Ans: b 75) The operator function used to overload the typecast operation must not mention any explicit argument in its header when implemented as member function. a) True b) False Ans: a

76) There can be more than one conversion function performing the same operation in the program. a) True b) False Ans: b

Você também pode gostar