Page 1 :
SE IT COMP OOP MCQs, Join Coders Community - https://t.me/Techvines_Coders_Union, , *** SANFOUNDRY OOP MCQ (1000+ MCQ), This set of Object Oriented Programming online test focuses on “OOP Basic, Concepts―., 1. Which was the first purely object oriented programming language developed?, a) Java, b) C++, c) SmallTalk, d) Kotlin, View Answer, Answer: c, Explanation: SmallTalk was the first programming language developed which was purely, object oriented. It was developed by Alan Kay. OOP concept came into the picture in, 1970’s., 2. Which of the following best defines a class?, a) Parent of an object, b) Instance of an object, c) Blueprint of an object, d) Scope of an object, View Answer, Answer: c, Explanation: A class is Blueprint of an object which describes/ shows all the functions and, data that are provided by an object of a specific class. It can’t be called as parent or, instance of an object. Class in general describes all the properties of an object., 3. Who invented OOP?, a) Alan Kay, b) Andrea Ferro, c) Dennis Ritchie, d) Adele Goldberg, View Answer
Page 2 :
Answer: a, Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development., Dennis invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan, actually had got rewarded for OOP., 4. What is the additional feature in classes that was not in structures?, a) Data members, b) Member functions, c) Static data allowed, d) Public access specifier, View Answer, Answer: b, Explanation: Member functions are allowed inside a class but were not present in structure, concept. Data members, static data and public access specifiers were present in structures too., 5. Which is not feature of OOP in general definitions?, a) Code reusability, b) Modularity, c) Duplicate/Redundant data, d) Efficient Code, View Answer, Answer: c, Explanation: Duplicate/Redundant data is dependent on programmer and hence can’t be, guaranteed by OOP. Code reusability is done using inheritance. Modularity is supported by, using different code files and classes. Codes are more efficient because of features of OOP., advertisement, , 6. Pure OOP can be implemented without using class in a program. (True or False), a) True, b) False, View Answer, Answer: b, Explanation: It’s false because for a program to be pure OO, everything must be written, inside classes. If this rule is violated, the program can’t be labelled as purely OO., 7. Which Feature of OOP illustrated the code reusability?, a) Polymorphism, b) Abstraction, c) Encapsulation, d) Inheritance, View Answer, Answer: d, Explanation: Using inheritance we can reuse the code already written and also can avoid, creation of many new functions or variables, as that can be done one time and be reused,, using classes.
Page 3 :
8. Which language does not support all 4 types of inheritance?, a) C++, b) Java, c) Kotlin, d) Small Talk, View Answer, Answer: b, Explanation: Java doesn’t support all 4 types of inheritance. It doesn’t support, multiple inheritance. But the multiple inheritance can be implemented using interfaces in, Java., 9. How many classes can be defined in a single program?, a) Only 1, b) Only 100, c) Only 999, d) As many as you want, View Answer, Answer: d, Explanation: Any number of classes can be defined inside a program, provided that their, names are different. In java, if public class is present then it must have the same name as that, of file., advertisement, , 10. When OOP concept did first came into picture?, a) 1970’s, b) 1980’s, c) 1993, d) 1995, View Answer, Answer: a, Explanation: OOP first came into picture in 1970’s by Alan and his team. Later it was, used by some programming languages and got implemented successfully, SmallTalk was first, language to use pure OOP and followed all rules strictly., 11. Why Java is Partially OOP language?, a) It supports usual declaration of primitive data types, b) It doesn’t support all types of inheritance, c) It allows code to be written outside classes, d) It does not support pointers, View Answer, Answer: a, Explanation: As Java supports usual declaration of data variables, it is partial implementation, of OOP. Because according to rules of OOP, object constructors must be used, even for, declaration of variables.
Page 4 :
12. Which concept of OOP is false for C++?, a) Code can be written without using classes, b) Code must contain at least one class, c) A class must have member functions, d) At least one object should be declared in code, View Answer, Answer: b, Explanation: In C++, it’s not necessary to use classes, and hence codes can be written, without using OOP concept. Classes may or may not contain member functions, so it’s, not a necessary condition in C++. And, an object can only be declared in a code if its class is, defined/included via header file., 13. Which header file is required in C++ to use OOP?, a) iostream.h, b) stdio.h, c) stdlib.h, d) OOP can be used without using any header file, View Answer, Answer: d, Explanation: We need not include any specific header file to use OOP concept in C++, only, specific functions used in code need their respective header files to be included or classes, should be defined if needed., advertisement, , 14. Which of the two features match each other?, a) Inheritance and Encapsulation, b) Encapsulation and Polymorphism, c) Encapsulation and Abstraction, d) Abstraction and Polymorphism, View Answer, Answer: c, Explanation: Encapsulation and Abstraction are similar features. Encapsulation is actually, binding all the properties in a single class or we can say hiding all the features of object, inside a class. And Abstraction is hiding unwanted data (for user) and showing only the data, required by the user of program., 15. Which feature allows open recursion, among the following?, a) Use of this pointer, b) Use of pointers, c) Use of pass by value, d) Use of parameterized constructor, View Answer, Answer: a, Explanation: Use of this pointer allows an object to call data and methods of itself whenever, needed. This helps us call the members of an object recursively, and differentiate the, variables of different scopes.
Page 5 :
Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for online tests, here is complete set of, 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, » Next - Object Oriented Programming Questions and Answers – Classes, Categories Object Oriented Programming MCQs Post navigation, MySQL Questions and Answers – Secure Connections, Object Oriented Programming Questions and Answers – Classes, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Exception Handling, 2. C++ Programming Examples on STL, 3. C Programming Examples, 4. Java Programming Examples on Data-Structures, 5. C Programming Examples on File Handling, 6. C# Programming Examples on Functions, 7. C# Programming Examples on Files, 8. Java Programming Examples on Utility Classes, 9. Java Programming Examples on File Handling, 10. Java Programming Examples on Java.Lang, 11. Java Programming Examples on Collections, 12. Ruby Programming Questions and Answers, 13. Java Programming Examples on Classes, 14. C# Programming Examples, 15. Java Programming Examples on Collection API, 16. Java Programming Examples on Networking, 17. Java Programming Examples, 18. C# Programming Examples on Inheritance, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Nested Class, advertisement, , Object Oriented Programming Questions, and Answers – Classes, « Prev, Next »
Page 6 :
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Classes―., 1. Which of the following is not type of class?, a) Abstract Class, b) Final Class, c) Start Class, d) String Class, View Answer, Answer: c, Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable,, wrapper, anonymous, input-output, string, system, network. We may further divide the, classes into parent class and subclass if inheritance is used., advertisement, , 2. Class is pass by _______, a) Value, b) Reference, c) Value or Reference, depending on program, d) Copy, View Answer, Answer: b, Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn’t, depend on the program., 3. What is default access specifier for data members or member functions declared within a, class without any specifier, in C++?, a) Private, b) Protected, c) Public, d) Depends on compiler, View Answer, Answer: a, Explanation: The data members and member functions are Private by default in C++ classes,, if none of the access specifier is used. It is actually made to increase the privacy of data., 4. Which is most appropriate comment on following class definition?, class Student, {, int a;, public : float a;, };, , a) Error : same variable name can’t be used twice, b) Error : Public must come first, c) Error : data types are different for same variable
Page 7 :
d) It is correct, View Answer, Answer: a, Explanation: Same variable can’t be defined twice in same scope. Even if the data types, are different, variable name must be different. There is no rule like Public member should, come first or last., advertisement, , 5. Which is known as a generic class?, a) Abstract class, b) Final class, c) Template class, d) Efficient Code, View Answer, Answer: c, Explanation: Template classes are known to be generic classes because those can be used for, any data type value and the same class can be used for all the variables of different data, types., 6. Size of a class is _____________, a) Sum of the size of all the variables declared inside the class, b) Sum of the size of all the variables along with inherited variables in the class, c) Size of the largest size of variable, d) Classes doesn’t have any size, View Answer, Answer: d, Explanation: Classes doesn’t have any size, actually the size of object of the class can be, defined. That is done only when an object is created and its constructor is called., 7. Which class can have member functions without their implementation?, a) Default class, b) String class, c) Template class, d) Abstract class, View Answer, Answer: d, Explanation: Abstract classes can have member functions with no implementation, where the, inheriting subclasses must implement those functions., 8. Which of the following describes a friend class?, a) Friend class can access all the private members of the class, of which it is a friend, b) Friend class can only access protected members of the class, of which it is a friend, c) Friend class don’t have any implementation, d) Friend class can’t access any data member of another class but can use it’s, methods, View Answer
Page 8 :
Answer: a, Explanation: A friend class can access all the private members of another class, of which it is, a friend. It is a special class provided to use when you need to reuse the data of a class but, don’t want that class to have those special functions., advertisement, , 9. What is the scope of a class nested inside another class?, a) Protected scope, b) Private scope, c) Global scope, d) Depends on access specifier and inheritance used, View Answer, Answer: d, Explanation: It depends on the access specifier and the type of inheritance used with the, class, because if the class is inherited then the nested class can be used by subclass too,, provided it’s not of private type., 10. Class with main() function can be inherited., a) True, b) False, View Answer, Answer: a, Explanation: The class containing main function can be inherited and hence the program can, be executed using the derived class names also in java., 11. Which among the following is false, for a member function of a class?, a) All member functions must be defined, b) Member functions can be defined inside or outside the class body, c) Member functions need not be declared inside the class definition, d) Member functions can be made friend to another class using the friend keyword, View Answer, Answer: c, Explanation: Member functions must be declared inside class body, though the definition can, be given outside the class body. There is no way to declare the member functions outside the, class., 12. Which syntax for class definition is wrong?, a) class student{ };, b) student class{ };, c) class student{ public: student(int a){ } };, d) class student{ student(int a){} };, View Answer, Answer: b, Explanation: Keyword class should come first. Class name should come after keyword class., Parameterized constructor definition depends on programmer so it can be left empty also.
Page 9 :
13. Which of the following pairs are similar?, a) Class and object, b) Class and structure, c) Structure and object, d) Structure and functions, View Answer, Answer: b, Explanation: Class and structure are similar to each other. Only major difference is that a, structure doesn’t have member functions whereas the class can have both data members, and member functions., advertisement, , 14. Which among the following is false for class features?, a) Classes may/may not have both data members and member functions, b) Class definition must be ended with a colon, c) Class can have only member functions with no data members, d) Class is similar to union and structures, View Answer, Answer: b, Explanation: Class definition must end with a semicolon, not colon. Class can have only, member functions in its body with no data members., 15. Instance of which type of class can’t be created?, a) Anonymous class, b) Nested class, c) Parent class, d) Abstract class, View Answer, Answer: d, Explanation: Instance of abstract class can’t be created as it will not have any constructor, of its own, hence while creating an instance of class, it can’t initialize the object, members. Actually the class inheriting the abstract class can have its instance because it will, have implementation of all members., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – OOPs Basic Concepts, » Next - Object Oriented Programming Questions and Answers – Objects
Page 10 :
Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – OOPs Basic Concepts, Object Oriented Programming Questions and Answers – Objects, advertisement, advertisement, , Recommended Posts:, 1. C++ Questions and Answers, 2. Java Programming Examples on Data-Structures, 3. C# Programming Examples on Files, 4. Ruby Programming Questions and Answers, 5. C# Programming Examples on LINQ, 6. C# Programming Examples on Exceptions, 7. Java Programming Examples on Multithreading, 8. C# Questions and Answers, 9. C# Programming Examples, 10. Java Programming Examples on Networking, 11. Java Programming Examples on File Handling, 12. C# Basic Programming Examples, 13. Java Programming Examples on Collections, 14. Java Programming Examples on Java.Lang, 15. Java Programming Examples, 16. C# Programming Examples on Functions, 17. Java Programming Examples on Utility Classes, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Objects, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Objects―., 1. Which definition best describes an object?, a) Instance of a class, b) Instance of itself, c) Child of a class, d) Overview of a class, View Answer
Page 11 :
Answer: a, Explanation: An object is instance of its class. It can be declared in the same way that a, variable is declared, only thing is you have to use class name as the data type., advertisement, , 2. How many objects can be declared of a specific class in a single program?, a) 32768, b) 127, c) 1, d) As many as you want, View Answer, Answer: d, Explanation: You can create as many objects of a specific class as you want, provided enough, memory is available., 3. Which among the following is false?, a) Object must be created before using members of a class, b) Memory for an object is allocated only after its constructor is called, c) Objects can’t be passed by reference, d) Objects size depends on its class data members, View Answer, Answer: c, Explanation: Objects can be passed by reference. Objects can be passed by value also. If the, object of a class is not created, we can’t use members of that class., 4. Which of the following is incorrect?, a) class student{ }s;, b) class student{ }; student s;, c) class student{ }s[];, d) class student{ }; student s[5];, View Answer, Answer: c, Explanation: The array must be specified with a size. You can’t declare object array, or, any other linear array without specifying its size. It’s a mandatory field., 5. The object can’t be __________, a) Passed by reference, b) Passed by value, c) Passed by copy, d) Passed as function, View Answer, Answer: d, Explanation: Object can’t be passed as function as it is an instance of some class, it’s, not a function. Object can be passed by reference, value or copy. There is no term defined as, pass as function for objects., advertisement
Page 12 :
6. What is size of the object of following class (64 bit system)?, class student {, , int rollno;, , char, , name[20];, , static int studentno;, , };, , a) 20, b) 22, c) 24, d) 28, View Answer, Answer: c, Explanation: The size of any object of student class will be of size 4+20=24, because static, members are not really considered as property of a single object. So static variables size will, not be added., 7. Functions can’t return objects., a) True, b) False, View Answer, Answer: b, Explanation: Functions can always return an object if the return type is same as that of object, being returned. Care has to be taken while writing the prototype of the function., 8. How members of an object are accessed?, a) Using dot operator/period symbol, b) Using scope resolution operator, c) Using member names directly, d) Using pointer only, View Answer, Answer: a, Explanation: Using dot operator after the name of object we can access its members. It is not, necessary to use the pointers. We can’t use the names directly because it may be used, outside the class., advertisement, , 9. If a local class is defined in a function, which of the following is true for an object of that, class?, a) Object is accessible outside the function, b) Object can be declared inside any other function, c) Object can be used to call other class members, d) Object can be used/accessed/declared locally in that function, View Answer, Answer: d, Explanation: For an object which belongs to a local class, it is mandatory to declare and use, the object within the function because the class is accessible locally within the class only.
Page 13 :
10. Which among the following is wrong?, a) class student{ }; student s;, b) abstract class student{ }; student s;, c) abstract class student{ }s[50000000];, d) abstract class student{ }; class toppers: public student{ }; topper t;, View Answer, Answer: b, Explanation: We can never create instance of an abstract class. Abstract classes doesn’t, have constructors and hence when an instance is created there is no facility to initialize its, members. Option d is correct because topper class is inheriting the base abstract class student,, and hence topper class object can be created easily., 11. Object declared in main() function _____________, a) Can be used by any other function, b) Can be used by main() function of any other program, c) Can’t be used by any other function, d) Can be accessed using scope resolution operator, View Answer, Answer: c, Explanation: The object declared in main() have local scope inside main() function only. It, can’t be used outside main() function. Scope resolution operator is used to access, globally declared variables/objects., 12. When an object is returned___________, a) A temporary object is created to return the value, b) The same object used in function is used to return the value, c) The Object can be returned without creation of temporary object, d) Object are returned implicitly, we can’t say how it happens inside program, View Answer, Answer: a, Explanation: A temporary object is created to return the value. It is created because the object, used in function is destroyed as soon as the function is returned. The temporary variable, returns the value and then gets destroyed., 13. Which among the following is correct?, a) class student{ }s1,s2; s1.student()=s2.student();, b) class student{ }s1; class topper{ }t1; s1=t1;, c) class student{ }s1,s2; s1=s2;, d) class student{ }s1; class topper{ }t1; s1.student()=s2.topper();, View Answer, Answer: c, Explanation: Only if the objects are of same class then their data can be copied from to, another using assignment operator. This actually comes under operator overloading. Class, constructors can’t be assigned any explicit value as in option class student{ }s1; class, topper{ }t1; s1=t1; and class student{ }s1; class topper{ }t1; s1.student()=s2.topper();., advertisement
Page 14 :
14. Which among following is correct for initializing the class below?, class student{, int marks;, int cgpa;, public: student(int i, int, marks=I;, cgpa=j, }, };, , j){, , a) student s[3]={ s(394, 9); s(394, 9); s(394,9); };, b) student s[2]={ s(394,9), s(222,5) };, c) student s[2]={ s1(392,9), s2(222,5) };, d) student s[2]={ s[392,9], s2[222,5] };, View Answer, Answer: b, Explanation: It is the way we can initialize the data members for an object array using, parameterized constructor. We can do this to pass our own intended values to initialize the, object array data., 15. Object can’t be used with pointers because they belong to user defined class, and, compiler can’t decide the type of data may be used inside the class., a) True, b) False, View Answer, Answer: b, Explanation: The explanation given is wrong because object can always be used with pointers, like with any other variables. Compiler doesn’t have to know the structure of the class to, use a pointer because the pointers only points to a memory address/stores that address., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Classes, » Next - Object Oriented Programming Questions and Answers – OOPs Features, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Classes, Object Oriented Programming Questions and Answers – OOPs Features, advertisement, advertisement
Page 15 :
Recommended Posts:, 1. C++ Questions and Answers, 2. Java Programming Examples on Event Handling, 3. Java Programming Examples on String Handling, 4. Java Programming Examples on Multithreading, 5. C Programming Examples on Bitwise Operations, 6. Java Programming Examples on Networking, 7. Java Programming Examples on Data-Structures, 8. C# Programming Examples on Strings, 9. Java Programming Examples on Utility Classes, 10. Ruby Programming Questions and Answers, 11. Java Programming Examples, 12. Java Programming Examples on Collections, 13. Java Programming Examples on File Handling, 14. Java Programming Examples on Java.Lang, 15. C# Programming Examples on Interfaces, 16. C# Programming Examples on LINQ, 17. C# Programming Examples on Functions, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – OOPs Features, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “OOP Features―., 1. Which feature of OOP indicates code reusability?, a) Encapsulation, b) Inheritance, c) Abstraction, d) Polymorphism, View Answer, Answer: b, Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are, meant to hide/group data into one element. Polymorphism is to indicate different tasks, performed by a single entity., advertisement
Page 16 :
2. If a function can perform more than 1 type of tasks, where the function name remains, same, which feature of OOP is used here?, a) Encapsulation, b) Inheritance, c) Polymorphism, d) Abstraction, View Answer, Answer: c, Explanation: For the feature given above, the OOP feature used is Polymorphism. Example, of polymorphism in real life is a kid, who can be a student, a son, a brother depending on, where he is., 3. If different properties and functions of a real world entity is grouped or embedded into a, single element, what is it called in OOP language?, a) Inheritance, b) Polymorphism, c) Abstraction, d) Encapsulation, View Answer, Answer: d, Explanation: It is Encapsulation, which groups different properties and functions of a real, world entity into single element. Abstraction, on other hand, is hiding of functional or exact, working of codes and showing only the things which are required by the user., 4. Which of the following is not a feature of pure OOP?, a) Classes must be used, b) Inheritance, c) Data may/may not be declared using object, d) Functions Overloading, View Answer, Answer: c, Explanation: Data must be declared using objects. Object usage is mandatory because it in, turn calls its constructors, which in turn must have a class defined. If object is not used, it is a, violation of pure OOP concept., 5. Which among the following doesn’t come under OOP concept?, a) Platform independent, b) Data binding, c) Message passing, d) Data hiding, View Answer, Answer: a, Explanation: Platform independence is not feature of OOP. C++ supports OOP but it’s, not a platform independent language. Platform independence depends on programming, language., advertisement
Page 17 :
6. Which feature of OOP is indicated by the following code?, class student{ int marks; };, class topper:public student{ int age;, , topper(int age){ this.age=age; } };, , a) Inheritance, b) Polymorphism, c) Inheritance and polymorphism, d) Encapsulation and Inheritance, View Answer, Answer: d, Explanation: Encapsulation is indicated by use of classes. Inheritance is shown by inheriting, the student class into topper class. Polymorphism is not shown here because we have defined, the constructor in the topper class but that doesn’t mean that default constructor is, overloaded., 7. Which feature may be violated if we don’t use classes in a program?, a) Inheritance can’t be implemented, b) Object must be used is violated, c) Encapsulation only is violated, d) Basically all the features of OOP gets violated, View Answer, Answer: d, Explanation: All the features are violated because Inheritance and Encapsulation won’t be, implemented. Polymorphism and Abstraction are still possible in some cases, but the main, features like data binding, object use and etc won’t be used hence the use of class is must, for OOP concept., 8. How many basic features of OOP are required for a programming language to be purely, OOP?, a) 7, b) 6, c) 5, d) 4, View Answer, Answer: a, Explanation: There are 7 basic features that define whether a programing language is pure, OOP or not. The 4 basic features are inheritance, polymorphism, encapsulation and, abstraction. Further, one is, object use is must, secondly, message passing and lastly,, Dynamic binding., advertisement, , 9. The feature by which one object can interact with another object is _____________, a) Data transfer, b) Data Binding, c) Message Passing
Page 18 :
d) Message reading, View Answer, Answer: c, Explanation: The interaction between two object is called the message passing feature. Data, transfer is not a feature of OOP. Also, message reading is not a feature of OOP., 10. ___________ underlines the feature of Polymorphism in a class., a) Nested class, b) Enclosing class, c) Inline function, d) Virtual Function, View Answer, Answer: d, Explanation: Virtual Functions can be defined in any class using the keyword virtual. All the, classes which inherit the class containing the virtual function, define the virtual function as, required. Redefining the function on all the derived classes according to class and use, represents polymorphism., 11. Which feature in OOP is used to allocate additional function to a predefined operator in, any language?, a) Operator Overloading, b) Function Overloading, c) Operator Overriding, d) Function Overriding, View Answer, Answer: a, Explanation: The feature is operator overloading. There is not a feature named operator, overriding specifically. Function overloading and overriding doesn’t give addition, function to any operator., 12. Which among doesn’t illustrates polymorphism?, a) Function overloading, b) Function overriding, c) Operator overloading, d) Virtual function, View Answer, Answer: b, Explanation: Function overriding doesn’t illustrate polymorphism because the functions, are actually different and theirs scopes are different. Function and operator overloading, illustrate proper polymorphism. Virtual functions show polymorphism because all the classes, which inherit virtual function, define the same function in different ways., 13. Exception handling is a feature of OOP., a) True, b) False, View Answer
Page 19 :
Answer: a, Explanation: Exception handling is a feature of OOP as it includes classes concept in most of, the cases. Also it may come handy while using inheritance., advertisement, , 14. Which among the following, for a pure OOP language, is true?, a) The language should follow 3 or more features of OOP, b) The language should follow at least 1 feature of OOP, c) The language must follow only 3 features of OOP, d) The language must follow all the rules of OOP, View Answer, Answer: d, Explanation: The language must follow all the rules of OOP to be called a purely OOP, language. Even if a single OOP feature is not followed, then it’s known to be a partially, OOP language., 15. Does OOP provide better security than POP?, a) Always true for any programming language, b) May not be true with respect to all programming languages, c) It depends on type of program, d) It’s vice-versa is true, View Answer, Answer: a, Explanation: It is always true as we have the facility of private and protected access, specifiers. Also, only the public and global data are available globally or else the program, should have proper permission to access the private data., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Objects, » Next - Object Oriented Programming Questions and Answers – Polymorphism, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Objects, Object Oriented Programming Questions and Answers – Polymorphism, advertisement, advertisement, , Recommended Posts:
Page 20 :
1. LISP Questions and Answers, 2. Java Programming Examples on Mathematical Functions, 3. Java Programming Examples on Collections, 4. C Programming Examples on Bitwise Operations, 5. Java Programming Examples on Java.Lang, 6. Java Programming Examples on Exception Handling, 7. Java Questions and Answers, 8. Programming Questions and Answers, 9. Java Programming Examples on Classes, 10. R Programming Questions and Answers, 11. C++ Questions and Answers, 12. C# Programming Examples on Functions, 13. C# Programming Examples, 14. C# Questions and Answers, 15. Java Programming Examples, 16. Python Questions and Answers, 17. Ruby Programming Questions and Answers, 18. Java Programming Examples on Inheritance, 19. C# Programming Examples on Inheritance, 20. PHP Questions & Answers – Basics of Object-Oriented PHP- 1, advertisement, , Object Oriented Programming Questions, and Answers – Polymorphism, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Polymorphism―., 1. Which among the following best describes polymorphism?, a) It is the ability for a message/data to be processed in more than one form, b) It is the ability for a message/data to be processed in only 1 form, c) It is the ability for many messages/data to be processed in one way, d) It is the ability for undefined message/data to be processed in at least one way, View Answer, Answer: a, Explanation: It is actually the ability for a message / data to be processed in more than one, form. The word polymorphism indicates many-forms. So if a single entity takes more than, one form, it is known as polymorphism., advertisement, , 2. What do you call the languages that support classes but not polymorphism?, a) Class based language, b) Procedure Oriented language, c) Object-based language
Page 21 :
d) If classes are supported, polymorphism will always be supported, View Answer, Answer: c, Explanation: The languages which support classes but doesn’t support polymorphism, are, known as object-based languages. Polymorphism is such an important feature, that is a, language doesn’t support this feature, it can’t be called as a OOP language., 3. Which among the following is the language which supports classes but not polymorphism?, a) SmallTalk, b) Java, c) C++, d) Ada, View Answer, Answer: d, Explanation: Ada is the language which supports the concept of classes but doesn’t, support the polymorphism feature. It is an object-based programming language. Note that, it’s not an OOP language., 4. If same message is passed to objects of several different classes and all of those can, respond in a different way, what is this feature called?, a) Inheritance, b) Overloading, c) Polymorphism, d) Overriding, View Answer, Answer: c, Explanation: The feature defined in question defines polymorphism features. Here the, different objects are capable of responding to the same message in different ways, hence, polymorphism., 5. Which class/set of classes can illustrate polymorphism in the following code?, abstract class student, {, public : int marks;, calc_grade();, }, class topper:public student, {, public : calc_grade(), {, return 10;, }, };, class average:public student, {, public : calc_grade(), {, return 20;, , advertisement
Page 22 :
}, };, class failed{ int marks; };, , a) Only class student can show polymorphism, b) Only class student and topper together can show polymorphism, c) All class student, topper and average together can show polymorphism, d) Class failed should also inherit class student for this code to work for polymorphism, View Answer, Answer: c, Explanation: Since Student class is abstract class and class topper and average are inheriting, student, class topper and average must define the function named calc_grade(); in abstract, class. Since both the definition are different in those classes, calc_grade() will work in, different way for same input from different objects. Hence it shows polymorphism., 6. Which type of function among the following shows polymorphism?, a) Inline function, b) Virtual function, c) Undefined functions, d) Class member functions, View Answer, Answer: b, Explanation: Only virtual functions among these can show polymorphism. Class member, functions can show polymorphism too but we should be sure that the same function is being, overloaded or is a function of abstract class or something like this, since we are not sure, about all these, we can’t say whether it can show polymorphism or not., 7. In case of using abstract class or function overloading, which function is supposed to be, called first?, a) Local function, b) Function with highest priority in compiler, c) Global function, d) Function with lowest priority because it might have been halted since long time, because, of low priority, View Answer, Answer: b, Explanation: Function with highest priority is called. Here, it’s not about the thread, scheduling in CPU, but it focuses on whether the function in local scope is present or not, or, if scope resolution is used in some way, or if the function matches the argument signature. So, all these things define which function has the highest priority to be called in runtime. Local, function could be one of the answer but we can’t say if someone have used pointer to, another function or same function name., 8. Which among the following can’t be used for polymorphism?, a) Static member functions, b) Member functions overloading, c) Predefined operator overloading
Page 23 :
d) Constructor overloading, View Answer, Answer: a, Explanation: Static member functions are not property of any object. Hence it can’t be, considered for overloading/overriding. For polymorphism, function must be property of, object, not only of class., advertisement, , 9. What is output of the following program?, class student, {, public : int marks;, void disp(), {, cout<<―its base class―, };, class topper:public student, {, public :, void disp(), {, cout<<―Its derived class―;, }, }, void main() { student s; topper t;, s.disp();, t.disp();, }, , a) Its base classIts derived class, b) Its base class Its derived class, c) Its derived classIts base class, d) Its derived class Its base class, View Answer, Answer: a, Explanation: You need to focus on how the output is going to be shown, no space will be, given after first message from base class. And then the message from derived class will be, printed. Function disp() in base class overrides the function of base class being derived., 10. Which among the following can show polymorphism?, a) Overloading ||, b) Overloading +=, c) Overloading <<, d) Overloading &&, View Answer, Answer: c, Explanation: Only insertion operator can be overloaded among all the given options. And the, polymorphism can be illustrated here only if any of these is applicable of being overloaded., Overloading is type of polymorphism.
Page 24 :
11. Find the output of the following program., advertisement, class education, {, char name[10];, public : disp(), {, cout<<―Its education system―;, }, class school:public education, {, public: void dsip(), {, cout<<―Its school education system―;, }, };, void main(), {, school s;, s.disp();, }, }, , a) Its school education system, b) Its education system, c) Its school education systemIts education system, d) Its education systemIts school education system, View Answer, Answer: a, Explanation: Notice that the function name in derived class is different from the function, name in base class. Hence when we call the disp() function, base class function is executed., No polymorphism is used here., 12. Polymorphism is possible in C language., a) True, b) False, View Answer, Answer: a, Explanation: It is possible to implement polymorphism in C language, even though it, doesn’t support class. We can use structures and then declare pointers which in turn, points to some function. In this way we simulate the functions like member functions but not, exactly member function. Now we can overload these functions, hence implementing, polymorphism in C language., 13. Which problem may arise if we use abstract class functions for polymorphism?, a) All classes are converted as abstract class, b) Derived class must be of abstract type, c) All the derived classes must implement the undefined functions, d) Derived classes can’t redefine the function, View Answer
Page 25 :
Answer: c, Explanation: The undefined functions must be defined is a problem, because one may need to, implement few undefined functions from abstract class, but he will have to define each of the, functions declared in abstract class. Being useless task, it is a problem sometimes., 14. Which among the following is not true for polymorphism?, a) It is feature of OOP, b) Ease in readability of program, c) Helps in redefining the same functionality, d) Increases overhead of function definition always, View Answer, Answer: d, Explanation: It never increases function definition overhead, one way or another if you, don’t use polymorphism, you will use the definition in some other way, so it actually, helps to write efficient codes., 15. If 2 classes derive one base class and redefine a function of base class, also overload, some operators inside class body. Among these two things of function and operator, overloading, where is polymorphism used?, a) Function overloading only, b) Operator overloading only, c) Both of these are using polymorphism, d) Either function overloading or operator overloading because polymorphism can be applied, only once in a program, View Answer, Answer: d, Explanation: Both of them are using polymorphism. It is not necessary that polymorphism, can be used only once in a program, it can be used anywhere, any number of times in a single, program., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – OOPs Features, » Next - Object Oriented Programming Questions and Answers – Encapsulation, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – OOPs Features, Object Oriented Programming Questions and Answers – Encapsulation, advertisement, advertisement
Page 26 :
Recommended Posts:, 1. C# Programming Examples on Strings, 2. Java Programming Examples on Data-Structures, 3. Java Programming Examples on Mathematical Functions, 4. Java Programming Examples on Utility Classes, 5. Python Questions and Answers, 6. Java Programming Examples on Exception Handling, 7. Java Programming Examples on Java.Lang, 8. C# Programming Examples, 9. C++ Questions and Answers, 10. C# Programming Examples on LINQ, 11. Ruby Programming Questions and Answers, 12. C Programming Examples on Stacks & Queues, 13. Java Programming Examples, 14. C++ Programming Examples on STL, 15. Java Programming Examples on Multithreading, 16. C# Questions and Answers, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Functions, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Private Member Functions, advertisement, , Object Oriented Programming Questions, and Answers – Encapsulation, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Encapsulation―., 1. Which among the following best describes encapsulation?, a) It is a way of combining various data members into a single unit, b) It is a way of combining various member functions into a single unit, c) It is a way of combining various data members and member functions into a single unit, which can operate on any data, d) It is a way of combining various data members and member functions that operate on those, data members into a single unit, View Answer, Answer: d, Explanation: It is a way of combining both data members and member functions, which, operate on those data members, into a single unit. We call it a class in OOP generally. This, feature have helped us modify the structures used in C language to be upgraded into class in, C++ and other languages.
Page 27 :
advertisement, , 2. If data members are private, what can we do to access them from the class object?, a) Create public member functions to access those data members, b) Create private member functions to access those data members, c) Create protected member functions to access those data members, d) Private data members can never be accessed from outside the class, View Answer, Answer: a, Explanation: We can define public member functions to access those private data members, and get their value for use or alteration. They can’t be accessed directly but is possible to, be access using member functions. This is done to ensure that the private data doesn’t get, modified accidentally., 3. While using encapsulation, which among the following is possible?, a) Code modification can be additional overhead, b) Data member’s data type can be changed without changing any other code, c) Data member’s type can’t be changed, or whole code have to be changed, d) Member functions can be used to change the data type of data members, View Answer, Answer: b, Explanation: Data member’s data type can be changed without changing any further, code. All the members using that data can continue in the same way without any, modification. Member functions can never change the data type of same class data members., 4. Which feature can be implemented using encapsulation?, a) Inheritance, b) Abstraction, c) Polymorphism, d) Overloading, View Answer, Answer: b, Explanation: Data abstraction can be achieved by using encapsulation. We can hide the, operation and structure of actual program from the user and can show only required, information by the user., 5. Find which of the following uses encapsulation?, a) void main(){ int a; void fun( int a=10; cout<<a); fun(); }, b) class student{ int a; public: int b;};, c) class student{int a; public: void disp(){ cout<<a;} };, d) struct topper{ char name[10]; public : int marks; }, View Answer, Answer: c, Explanation: It is the class which uses both the data members and member functions being, declared inside a single unit. Only data members can be there in structures also. And the, encapsulation can only be illustrated if some data/operations are associated within class.
Page 28 :
advertisement, , 6. Encapsulation helps in writing ___________ classes in java., a) Mutable, b) Abstract, c) Wrapper, d) Immutable, View Answer, Answer: d, Explanation: Immutable classes are used for caching purpose generally. And it can be created, by making the class as final and making all its members private., 7. Which among the following should be encapsulated?, a) The data which is prone to change is near future, b) The data prone to change in long terms, c) The data which is intended to be changed, d) The data which belongs to some other class, View Answer, Answer: a, Explanation: The data prone to change in near future is usually encapsulated so that it, doesn’t get changed accidentally. We encapsulate the data to hide the critical working of, program from outside world., 8. How can Encapsulation be achieved?, a) Using Access Specifiers, b) Using only private members, c) Using inheritance, d) Using Abstraction, View Answer, Answer: a, Explanation: Using access specifiers we can achieve encapsulation. Using this we can in turn, implement data abstraction. It’s not necessary that we only use private access., 9. Which among the following violates the principle of encapsulation almost always?, a) Local variables, b) Global variables, c) Public variables, d) Array variables, View Answer, Answer: b, Explanation: Global variables almost always violates the principles of encapsulation., Encapsulation says the data should be accessed only by required set of elements. But global, variable is accessible everywhere, also it is most prone to changes. It doesn’t hide the, internal working of program.
Page 29 :
10. Which among the following would destroy the encapsulation mechanism if it was allowed, in programming?, a) Using access declaration for private members of base class, b) Using access declaration for public members of base class, c) Using access declaration for local variable of main() function, d) Using access declaration for global variables, View Answer, Answer: a, Explanation: If using access declaration for private members of base class was allowed in, programming, it would have destroyed whole concept of encapsulation. As if it was possible,, any class which gets inherited privately, would have been able to inherit the private members, of base class, and hence could access each and every member of base class., advertisement, , 11. Which among the following can be a concept against encapsulation rules?, a) Using function pointers, b) Using char* string pointer to be passed to non-member function, c) Using object array, d) Using any kind of pointer/array address in passing to another function, View Answer, Answer: d, Explanation: If we use any kind of array or pointer as data member which should not be, changed, but in some case its address is passed to some other function or similar variable., There are chances to modify its whole data easily. Hence Against encapsulation., 12. Consider the following code and select the correct option., class student, {, int marks;, public : int* fun(), {, return &marks;, }, };, main(), {, student s;, int *ptr=c.fun();, return 0;, }, , a) This code is good to go, b) This code may result in undesirable conditions, c) This code will generate error, d) This code violates encapsulation, View Answer, Answer: d, Explanation: This code violates the encapsulation. By this code we can get the address of the
Page 30 :
private member of the class, hence we can change the value of private member, which is, against the rules., 13. Consider the code and select the wrong choice., class hero, {, char name[10];, public : void disp(), {, cout<<name;, }, };, , advertisement, , a) This maintains encapsulation, b) This code doesn’t maintain encapsulation, c) This code is vulnerable, d) This code gives error, View Answer, Answer: a, Explanation: This code maintains encapsulation. Here the private member is kept private., Outside code can’t access the private members of class. Only objects of this class will be, able to access the public member function at maximum., 14. Encapsulation is the way to add functions in a user defined structure., a) True, b) False, View Answer, Answer: b, Explanation: False, because we can’t call these structures if member functions are, involved, it must be called class. Also, it is not just about adding functions, it’s about, binding data and functions together., 15. Using encapsulation data security is ___________, a) Not ensured, b) Ensured to some extent, c) Purely ensured, d) Very low, View Answer, Answer: b, Explanation: The encapsulation can only ensure data security to some extent. If pointer and, addresses are misused, it may violate encapsulation. Use of global variables also makes the, program vulnerable, hence we can’t say that encapsulation gives pure security., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs).
Page 31 :
To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Polymorphism, » Next - Object Oriented Programming Questions and Answers – Abstraction, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Polymorphism, Object Oriented Programming Questions and Answers – Abstraction, advertisement, advertisement, , Recommended Posts:, 1. R Programming Questions and Answers, 2. Python Questions and Answers, 3. Java Programming Examples on File Handling, 4. C# Programming Examples on Inheritance, 5. C# Programming Examples, 6. Python Programming Examples on Linked Lists, 7. Java Programming Examples, 8. C Programming Examples on File Handling, 9. C# Programming Examples on Files, 10. Java Programming Examples on Multithreading, 11. C# Programming Examples on Functions, 12. Ruby Programming Questions and Answers, 13. Java Programming Examples on Java.Lang, 14. C Programming Examples on Linked List, 15. C# Basic Programming Examples, 16. C Programming Examples on Stacks & Queues, 17. Java Programming Examples on Collections, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Abstraction, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Abstraction―.
Page 32 :
1. Which among the following best defines abstraction?, a) Hiding the implementation, b) Showing the important data, c) Hiding the important data, d) Hiding the implementation and showing only the features, View Answer, Answer: d, Explanation: It includes hiding the implementation part and showing only the required data, and features to the user. It is done to hide the implementation complexity and details from the, user. And to provide a good interface in programming., advertisement, , 2. Hiding the implementation complexity can ____________, a) Make the programming easy, b) Make the programming complex, c) Provide more number of features, d) Provide better features, View Answer, Answer: a, Explanation: It can make programming easy. The programming need not know how the, inbuilt functions are working but can use those complex functions directly in the program. It, doesn’t provide more number of features or better features., 3. Class is _________ abstraction., a) Object, b) Logical, c) Real, d) Hypothetical, View Answer, Answer: b, Explanation: Class is logical abstraction because it provides a logical structure for all of its, objects. It gives an overview of the features of an object., 4. Object is ________ abstraction., a) Object, b) Logical, c) Real, d) Hypothetical, View Answer, Answer: c, Explanation: Object is real abstraction because it actually contains those features of class. It, is the implementation of overview given by class. Hence the class is logical abstraction and, its object is real., 5. Abstraction gives higher degree of ________, a) Class usage
Page 33 :
b) Program complexity, c) Idealized interface, d) Unstable interface, View Answer, Answer: c, Explanation: It is to idealize the interface. In this way the programmer can use the, programming features more efficiently and can code better. It can’t increase the program, complexity, as the feature itself is made to hide it., advertisement, , 6. Abstraction can apply to ____________, a) Control and data, b) Only data, c) Only control, d) Classes, View Answer, Answer: a, Explanation: Abstraction applies to both. Control abstraction involves use of subroutines and, control flow abstraction. Data abstraction involves handling pieces of data in meaningful, ways., 7. Which among the following can be viewed as combination of abstraction of data and code., a) Class, b) Object, c) Inheritance, d) Interfaces, View Answer, Answer: b, Explanation: Object can be viewed as abstraction of data and code. It uses data members and, their functioning as data abstraction. Code abstraction as use of object of inbuilt class., 8. Abstraction principle includes___________, a) Use abstraction at its minimum, b) Use abstraction to avoid longer codes, c) Use abstraction whenever possible to avoid duplication, d) Use abstraction whenever possible to achieve OOP, View Answer, Answer: c, Explanation: Abstraction principle includes use of abstraction to avoid duplication (usually of, code). It this way the program doesn’t contain any redundant functions and make the, program efficient., 9. Higher the level of abstraction, higher are the details., a) True, b) False, View Answer
Page 34 :
Answer: b, Explanation: Higher the level of abstraction, lower are the details. The best way to understand, this is to consider a whole system that is highest level of abstraction as it hides everything, inside. And next lower level would contain few of the computer components and so on., advertisement, , 10. Encapsulation and abstraction differ as ____________, a) Binding and Hiding respectively, b) Hiding and Binding respectively, c) Can be used any way, d) Hiding and hiding respectively, View Answer, Answer: a, Explanation: Abstraction is hiding the complex code. For example, we directly use cout, object in C++ but we don’t know how is it actually implemented. Encapsulation is data, binding, as in, we try to combine a similar type of data and functions together., 11. In terms of stream and files ____________, a) Abstraction is called a stream and device is called a file, b) Abstraction is called a file and device is called a stream, c) Abstraction can be called both file and stream, d) Abstraction can’t be defined in terms of files and stream, View Answer, Answer: a, Explanation: Abstraction is called stream to provide a level of complexity hiding, for how the, files operations are actually done. Actual devices are called file because in one way or, another, those can be considered as single entity and there is nothing hidden., 12. If two classes combine some private data members and provides public member functions, to access and manipulate those data members. Where is abstraction used?, a) Using private access specifier for data members, b) Using class concept with both data members and member functions, c) Using public member functions to access and manipulate the data members, d) Data is not sufficient to decide what is being used, View Answer, Answer: c, Explanation: It is the concept of hiding program complexity and actual working in, background. Hence use of public member functions illustrates abstraction here., 13. A phone is made up of many components like motherboard, camera, sensors and etc. If, the processor represents all the functioning of phone, display shows the display only, and the, phone is represented as a whole. Which among the following have highest level of, abstraction?, a) Motherboard, b) Display, c) Camera
Page 35 :
d) Phone, View Answer, Answer: d, Explanation: Phone as a whole have the highest level of abstraction. This is because the, phone being a single unit represents the whole system. Whereas motherboard, display and, camera are its components., advertisement, , 14. Which among the following is not a level of abstraction?, a) Logical level, b) Physical level, c) View level, d) External level, View Answer, Answer: d, Explanation: Abstraction is generally divided into 3 different levels, namely, logical, physical, and view level. External level is not defined in terms of abstraction., 15. Using higher degree of abstraction __________, a) May get unsafe, b) May reduce readability, c) Can be safer, d) Can increase vulnerability, View Answer, Answer: c, Explanation: It will make the code safer. One may think it reduces the readability, but the fact, is, it actually helps us understand the code better. We don’t have to read the complex, code which is of no use in understanding the program., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Encapsulation, » Next - Object Oriented Programming Questions and Answers – Constructors, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Encapsulation, Object Oriented Programming Questions and Answers – Constructors, advertisement, advertisement
Page 36 :
Recommended Posts:, 1. C# Programming Examples on Networking, 2. C Programming Examples, 3. C Programming Examples on Mathematical Functions, 4. C Programming Examples on Stacks & Queues, 5. Java Programming Examples on Arrays, 6. C# Programming Examples on Strings, 7. C Programming Examples without using Recursion, 8. Python Programming Examples on Linked Lists, 9. Java Programming Examples, 10. Java Programming Examples on Collections, 11. C# Programming Examples on LINQ, 12. C Programming Examples on Linked List, 13. C# Programming Examples on Inheritance, 14. C# Programming Examples on Files, 15. C# Programming Examples, 16. Java Programming Examples on Classes, 17. Java Programming Examples on File Handling, 18. Java Programming Examples on Inheritance, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers – Nested Class, advertisement, , Object Oriented Programming Questions, and Answers – Constructors, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Constructors―., 1. Which among the following is called first, automatically, whenever an object is created?, a) Class, b) Constructor, c) New, d) Trigger, View Answer, Answer: b, Explanation: Constructors are the member functions which are called automatically whenever, an object is created. It is a mandatory functions to be called for an object to be created as this, helps in initializing the object to a legal initial value for the class., advertisement
Page 37 :
2. Which among the following is not a necessary condition for constructors?, a) Its name must be same as that of class, b) It must not have any return type, c) It must contain a definition body, d) It can contains arguments, View Answer, Answer: c, Explanation: Constructors are predefined implicitly, even if the programmer doesn’t, define any of them. Even if the programmer declares a constructor, it’s not necessary that, it must contain some definition., 3. Which among the following is correct?, a) class student{ public: int student(){} };, b) class student{ public: void student (){} };, c) class student{ public: student{}{} };, d) class student{ public: student(){} };, View Answer, Answer: d, Explanation: The constructors must not have any return type. Also, the body may or may not, contain any body. Defining default constructor is optional, if you are not using any other, constructor., 4. In which access should a constructor be defined, so that object of the class can be created, in any function?, a) Public, b) Protected, c) Private, d) Any access specifier will work, View Answer, Answer: a, Explanation: Constructor function should be available to all the parts of program where the, object is to be created. Hence it is advised to define it in public access, so that any other, function is able to create objects., 5. How many types of constructors are available for use in general (with respect to, parameters)?, a) 2, b) 3, c) 4, d) 5, View Answer, Answer: a, Explanation: Two types of constructors are defined generally, namely, default constructor, and parameterized constructor. Default constructor is not necessary to be defined always., advertisement
Page 38 :
6. If a programmer defines a class and defines a default value parameterized constructor, inside it., He has not defined any default constructor. And then he try to create the object without, passing arguments, which among the following will be correct?, a) It will not create the object (as parameterized constructor is used), b) It will create the object (as the default arguments are passed), c) It will not create the object (as the default constructor is not defined), d) It will create the object (as at least some constructor is defined), View Answer, Answer: b, Explanation: It will create the object without any problem, because the default arguments use, the default value if no value is passed. Hence it is equal to default constructor with zero, parameters. But it will not create the object if signature doesn’t match., 7. Default constructor must be defined, if parameterized constructor is defined and the object, is to be created without arguments., a) True, b) False, View Answer, Answer: a, Explanation: If the object is create without arguments and only parameterized constructors, are used, compiler will give an error as there is no default constructor defined. And some, constructor must be called so as to create an object in memory., 8. If class C inherits class B. And B has inherited class A. Then while creating the object of, class C, what will be the sequence of constructors getting called?, a) Constructor of C then B, finally of A, b) Constructor of A then C, finally of B, c) Constructor of C then A, finally B, d) Constructor of A then B, finally C, View Answer, Answer: d, Explanation: While creating the object of class C, its constructor would be called by default., But, if the class is inheriting some other class, firstly the parent class constructor will be, called so that all the data is initialized that is being inherited., 9. In multiple inheritance, if class C inherits two classes A and B as follows, which class, constructor will be called first?, class A{ };, class B{ };, class C: public A, public B{, , a) A(), b) B(), c) C(), , };
Page 39 :
d) Can’t be determined, View Answer, Answer: a, Explanation: Constructor of class A will be called first. This is because the constructors in, multiple inheritance are called in the sequence in which they are written to be inherited. Here, A is written first, hence it is called first., advertisement, , 10. Which among the following is true for copy constructor?, a) The argument object is passed by reference, b) It can be defined with zero arguments, c) Used when an object is passed by value to a function, d) Used when a function returns an object, View Answer, Answer: b, Explanation: It can’t be defined with zero number of arguments. This is because to copy, one object to another, the object must be mentioned so that compiler can take values from, that object., 11. If the object is passed by value to a copy constructor?, a) Only public members will be accessible to be copied, b) That will work normally, c) Compiler will give out of memory error, d) Data stored in data members won’t be accessible, View Answer, Answer: c, Explanation: Compiler runs out of memory. This is because while passing the argument by, value, a constructor of the object will be called. That in turn called another object constructor, for values, and this goes on. This is like a constructor call to itself, and this goes on infinite, times, hence it must be passed by reference, so that the constructor is not called., 12. Which object will be created first?, class student, {, int marks;, };, student s1, s2, s3;, , a) s1 then s2 then s3, b) s3 then s2 then s1, c) s2 then s3 then s1, d) all are created at same time, View Answer, Answer: a, Explanation: The objects are created in the sequence of how they are written. This happens
Page 40 :
because the constructors are called in the sequence of how the objects are mentioned. This is, done in sequence., advertisement, , 13. Which among the following helps to create a temporary instance?, a) Implicit call to a default constructor, b) Explicit call to a copy constructor, c) Implicit call to a parameterized constructor, d) Explicit call to a constructor, View Answer, Answer: d, Explanation: Explicit call to a constructor can let you create a temporary instance. This is, because the temporary instances doesn’t have any name. Those are deleted from memory, as soon as their reference is removed., 14. Which among the following is correct for the class defined below?, class student, {, int marks;, public: student(){}, student(int x), {, marks=x;, }, };, main(), {, student s1(100);, student s2();, student s3=100;, return 0;, }, , a) Object s3, syntax error, b) Only object s1 and s2 will be created, c) Program runs and all objects are created, d) Program will give compile time error, View Answer, Answer: c, Explanation: It is a special case of constructor with only 1 argument. While calling a, constructor with one argument, you are actually implicitly creating a conversion from the, argument type to the type of class. Hence you can directly specify the value of that one, argument with assignment operator., 15. For constructor overloading, each constructor must differ in ___________ and, __________, a) Number of arguments and type of arguments, b) Number of arguments and return type, c) Return type and type of arguments
Page 41 :
d) Return type and definition, View Answer, Answer: a, Explanation: Each constructor must differ in the number of arguments it accepts and the type, of arguments. This actually defines the constructor signature. This helps to remove the, ambiguity and define a unique constructor as required., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Abstraction, » Next - Object Oriented Programming Questions and Answers – Types of Constructors, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Abstraction, Object Oriented Programming Questions and Answers – Types of Constructors, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Delegates, 2. C# Programming Examples on Mathematics, 3. Java Programming Examples on Mathematical Functions, 4. Java Programming Examples on Event Handling, 5. C Programming Examples on File Handling, 6. Java Programming Examples, 7. C# Programming Examples on Strings, 8. C# Programming Examples on Events, 9. Java Programming Examples on Utility Classes, 10. Java Programming Examples on Networking, 11. C# Programming Examples on LINQ, 12. Java Programming Examples on Collections, 13. Java Programming Examples on Multithreading, 14. C# Programming Examples on Functions, 15. Java Programming Examples on Java.Lang, 16. Java Programming Examples on File Handling, 17. Java Programming Examples on Exception Handling, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers
Page 42 :
advertisement, , Object Oriented Programming Questions, and Answers – Types of Constructors, « Prev, Next », , This set of Object Oriented Programming online quiz focuses on “Types of, Constructors―., 1. How many types of constructors are available, in general, in any language?, a) 2, b) 3, c) 4, d) 5, View Answer, Answer: b, Explanation: There are 3 types of constructors in general, namely, default constructors,, parameterized constructors and copy constructors. Default one is called whenever an object is, created without arguments., advertisement, , 2. Choose the correct option for the following code., class student, {, int marks;, }, student s1;, student s2=2;, , a) Object s1 should be passed with argument, b) Object s2 should not be declared, c) Object s2 will not be created, but program runs, d) Program gives compile time error, View Answer, Answer: d, Explanation: The object s2 can be assigned with one value only if a single argument, constructor is defined in class, but here, it can’t be done as no constructor is defined., Hence every object must be declare or created without using arguments., 3. Which constructor is called while assigning some object with another?, a) Default, b) Parameterized, c) Copy, d) Direct assignment is used, View Answer
Page 43 :
Answer: c, Explanation: Copy constructor is used while an object is assigned with another. This is, mandatory since we can’t decide which member should be assigned to which member, value. By using copy constructor, we can assign the values in required form., advertisement, , 4. It’s necessary to pass object by reference in copy constructor because ____________, a) Constructor is not called in pass by reference, b) Constructor is called in pass by reference only, c) It passes the address of new constructor to be created, d) It passes the address of new object to be created, View Answer, Answer: a, Explanation: Object must be passed by reference to copy constructor because constructor is, not called in pass by reference. Otherwise, in pass by value, a temporary object will be, created which in turn will try to call its constructor that is already being used. This results in, creating infinite number of objects and hence memory shortage error will be shown., 5. Which specifier applies only to the constructors?, a) Public, b) Protected, c) Implicit, d) Explicit, View Answer, Answer: d, Explanation: The keyword explicit can be used while defining the constructor only. This is, used to suppress the implicit call to the constructor. It ensures that the constructors are being, called with the default syntax only (i.e. only by using object and constructor name)., 6. Which among the following is true?, a) Default constructor can’t be defined by the programmer, b) Default parameters constructor isn’t equivalent to the default constructor, c) Default constructor can be called explicitly, d) Default constructor is and always called implicitly only, View Answer, Answer: c, Explanation: Default constructors can be called explicitly anytime. They are specifically used, to allocate memory space for the object in memory, in general. It is not necessary that these, should always be called implicitly., 7. Which type of constructor can’t have a return type?, a) Default, b) Parameterized, c) Copy, d) Constructors don’t have a return type, View Answer
Page 44 :
Answer: d, Explanation: Constructors don’t return any value. Those are special functions, whose, return type is not defined, not even void. This is so because the constructors are meant to, initialize the members of class and not to perform some task which can return some value to, newly created object., 8. Why do we use static constructors?, a) To initialize the static members of class, b) To initialize all the members with static value, c) To delete the static members when not required, d) To clear all the static members initialized values, View Answer, Answer: a, Explanation: Static constructors help in initializing the static members of the class. This is, provided because the static members are not considered to be property of the object, rather, they are considered as the property of class., advertisement, , 9. When and how many times a static constructor is called?, a) Created at time of object destruction, b) Called at first time when an object is created and only one time, c) Called at first time when an object is created and called with every new object creation, d) Called whenever an object go out of scope, View Answer, Answer: b, Explanation: Those are called at very first call of object creation. That is called only one time, because the value of static members must be retained and continued from the time it gets, created., 10. Which among the following is true for static constructor?, a) Static constructors are called with every new object, b) Static constructors are used initialize data members to zero always, c) Static constructors can’t be parameterized constructors, d) Static constructors can be used to initialize the non-static members also, View Answer, Answer: c, Explanation: Static constructors can’t be parameterized constructors. Those are used to, initialize the value of static members only. And that must be a definite value. Accepting, arguments may make it possible that static members loses their value with every new object, being created., 11. Within a class, only one static constructor can be created., a) True, b) False, View Answer
Page 45 :
Answer: a, Explanation: Since the static constructors are can’t be parameterized, they can’t be, overloaded. Having this case, only one constructor will be possible to be created in a local, scope, because the signature will always be same and hence it will not be possible to overload, static constructor., 12. Default constructor initializes all data members as ___________, a) All numeric member with some garbage values and string to random string, b) All numeric member with some garbage values and string to null, c) All numeric member with zero and strings to random value, d) All numeric member with zero and strings to null, View Answer, Answer: d, Explanation: Default constructor, which even the programmer doesn’t define, always, initialize the values as zero if numeric and null if string. This is done so as to avoid the, accidental values to change the conditional statements being used and similar conditions., 13. When is the static constructor called?, a) After the first instance is created, b) Before default constructor call of first instance, c) Before first instance is created, d) At time of creation of first instance, View Answer, Answer: c, Explanation: The static constructor is called before creation of the first instance of that class., This is done so that even the first instance can use the static value of the static members of, the class and manipulate as required., advertisement, , 14. If constructors of a class are defined in private access, then __________, a) The class can’t be inherited, b) The class can be inherited, c) Instance can be created only in another class, d) Instance can be created anywhere in the program, View Answer, Answer: a, Explanation: If the constructors are defined in private access, then the class can’t be, inherited by other classes. This is useful when the class contains static members only. The, instances can never be created., 15. Which among the following is correct, based on the given code below?, class student, {, int marks;, public : student(), {, cout<<―New student details can be added now―;
Page 46 :
}, };, student s1;, , a) Cout can’t be used inside the constructor, b) Constructor must contain only initializations, c) This program works fine, d) This program produces errors, View Answer, Answer: c, Explanation: This program will work fine. This is because it is not mandatory that a, constructor must contain only initialization only. If you want to perform a task on each, instance being created, that code can be written inside the constructor., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for online Quizzes, here is complete, set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Constructors, » Next - Object Oriented Programming Questions and Answers – Copy Constructor, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Constructors, Object Oriented Programming Questions and Answers – Copy Constructor, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Events, 2. Python Programming Examples on Trees, 3. C Programming Examples on File Handling, 4. Java Programming Examples on String Handling, 5. Java Programming Examples, 6. C# Programming Examples on Files, 7. Java Programming Examples on Networking, 8. C# Basic Programming Examples, 9. Java Programming Examples on Utility Classes, 10. Java Programming Examples on Collections, 11. C# Programming Examples on Functions, 12. Java Programming Examples on Exception Handling, 13. C# Programming Examples on Mathematics, 14. C# Programming Examples on Arrays, 15. Java Programming Examples on Multithreading
Page 47 :
16. Java Programming Examples on File Handling, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Copy Constructor, « Prev, Next », , This set of Basic Object Oriented Programming Questions and Answers focuses on “Copy, Constructor―., 1. Copy constructor is a constructor which ________________, a) Creates an object by copying values from any other object of same class, b) Creates an object by copying values from first object created for that class, c) Creates an object by copying values from another object of another class, d) Creates an object by initializing it with another previously created object of same class, View Answer, Answer: d, Explanation: The object that has to be copied to new object must be previously created. The, new object gets initialized with the same values as that of the object mentioned for being, copied. The exact copy is made with values., advertisement, , 2. The copy constructor can be used to ____________, a) Initialize one object from another object of same type, b) Initialize one object from another object of different type, c) Initialize more than one object from another object of same type at a time, d) Initialize all the objects of a class to another object of another class, View Answer, Answer: a, Explanation: The copy constructor has the most basic function to initialize the members of an, object with same values as that of some previously created object. The object must be of, same class., 3. If two classes have exactly same data members and member function and only they differ, by class name. Can copy constructor be used to initialize one class object with another class, object?, a) Yes, possible, b) Yes, because the members are same, c) No, not possible
Page 48 :
d) No, but possible if constructor is also same, View Answer, Answer: c, Explanation: The restriction for copy constructor is that it must be used with the object of, same class. Even if the classes are exactly same the constructor won’t be able to access, all the members of another class. Hence we can’t use object of another class for, initialization., 4. The copy constructors can be used to ________, a) Copy an object so that it can be passed to a class, b) Copy an object so that it can be passed to a function, c) Copy an object so that it can be passed to another primitive type variable, d) Copy an object for type casting, View Answer, Answer: b, Explanation: When an object is passed to a function, actually its copy is made in the function., To copy the values, copy constructor is used. Hence the object being passed and object being, used in function are different., 5. Which returning an object, we can use ____________, a) Default constructor, b) Zero argument constructor, c) Parameterized constructor, d) Copy constructor, View Answer, Answer: d, Explanation: While returning an object we can use the copy constructor. When we assign the, return value to another object of same class then this copy constructor will be used. And all, the members will be assigned the same values as that of the object being returned., advertisement, , 6. If programmer doesn’t define any copy constructor then _____________, a) Compiler provides an implicit copy constructor, b) Compiler gives an error, c) The objects can’t be assigned with another objects, d) The program gives run time error if copying is used, View Answer, Answer: a, Explanation: The compiler provides an implicit copy constructor. It is not mandatory to, always create an explicit copy constructor. The values are copied using implicit constructor, only., 7. If a class implements some dynamic memory allocations and pointers then _____________, a) Copy constructor must be defined, b) Copy constructor must not be defined, c) Copy constructor can’t be defined
Page 49 :
d) Copy constructor will not be used, View Answer, Answer: a, Explanation: In the case where dynamic memory allocation is used, the copy constructor, definition must be given. The implicit copy constructor is not capable of manipulating the, dynamic memory and pointers. Explicit definition allows to manipulate the data as required., 8. What is the syntax of copy constructor?, a) classname (classname &obj){ /*constructor definition*/ }, b) classname (cont classname obj){ /*constructor definition*/ }, c) classname (cont classname &obj){ /*constructor definition*/ }, d) classname (cont &obj){ /*constructor definition*/ }, View Answer, Answer: c, Explanation: The syntax must contain the class name first, followed by the classname as type, and &object within parenthesis. Then comes the constructor body. The definition can be, given as per requirements., 9. Object being passed to a copy constructor ___________, a) Must be passed by reference, b) Must be passed by value, c) Must be passed with integer type, d) Must not be mentioned in parameter list, View Answer, Answer: a, Explanation: This is mandatory to pass the object by reference. Otherwise, the object will try, to create another object to copy its values, in turn a constructor will be called, and this will, keep on calling itself. This will cause the compiler to give out of memory error., advertisement, , 10. Out of memory error is given when the object _____________ to the copy constructor., a) Is passed with & symbol, b) Is passed by reference, c) Is passed as <classname &obj>, d) Is not passed by reference, View Answer, Answer: d, Explanation: All the options given, directly or indirectly indicate that the object is being, passed by reference. And if object is not passed by reference then the out of memory error is, produced. Due to infinite constructor call of itself., 11. Copy constructor will be called whenever the compiler __________, a) Generates implicit code, b) Generates member function calls, c) Generates temporary object
Page 50 :
d) Generates object operations, View Answer, Answer: c, Explanation: Whenever the compiler creates a temporary object, copy constructor is used to, copy the values from existing object to the temporary object., 12. The deep copy is possible only with the help of __________, a) Implicit copy constructor, b) User defined copy constructor, c) Parameterized constructor, d) Default constructor, View Answer, Answer: b, Explanation: While using explicit copy constructor, the pointers of copied object point to the, intended memory location. This is assured since the programmers themselves manipulate the, addresses., 13. Can a copy constructor be made private?, a) Yes, always, b) Yes, if no other constructor is defined, c) No, never, d) No, private members can’t be accessed, View Answer, Answer: a, Explanation: The copy constructor can be defined as private. If we make it private then the, objects of the class can’t be copied. It can be used when a class used dynamic memory, allocation., advertisement, , 14. The arguments to a copy constructor _____________, a) Must be const, b) Must not be cosnt, c) Must be integer type, d) Must be static, View Answer, Answer: a, Explanation: The object should not be modified in the copy constructor. Because the object, itself is being copied. When the object is returned from a function, the object must be a, constant otherwise the compiler creates a temporary object which can die anytime., 15. Copy constructors are overloaded constructors., a) True, b) False, View Answer
Page 51 :
Answer: a, Explanation: The copy constructors are always overloaded constructors. They have to be. All, the classes have a default constructor and other constructors are basically overloaded, constructors., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice basic questions and answers on all areas of Object Oriented Programming, here is, complete set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Types of Constructors, » Next - Object Oriented Programming Questions and Answers – Overloading, Constructors, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Types of Constructors, Object Oriented Programming Questions and Answers – Overloading Constructors, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Data-Structures, 2. C Programming Examples using Recursion, 3. Java Programming Examples on String Handling, 4. C# Programming Examples on Functions, 5. C# Programming Examples on Events, 6. Java Programming Examples, 7. Java Programming Examples on Utility Classes, 8. C# Programming Examples on Mathematics, 9. C Programming Examples on File Handling, 10. Java Programming Examples on Multithreading, 11. Java Programming Examples on Collections, 12. C# Programming Examples on Files, 13. Java Programming Examples on Networking, 14. Java Programming Examples on File Handling, 15. Java Programming Examples on Exception Handling, 16. C# Programming Examples on Arrays, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement
Page 52 :
Object Oriented Programming Questions, and Answers – Overloading Constructors, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Overloading Constructors―., 1. Which among the following best describes constructor overloading?, a) Defining one constructor in each class of a program, b) Defining more than one constructor in single class, c) Defining more than one constructor in single class with different signature, d) Defining destructor with each constructor, View Answer, Answer: c, Explanation: If more than one constructors are defined in a class with same signature, then, that results in error. The signatures must be different. So that the constructors can be, differentiated., advertisement, , 2. Can constructors be overloaded in derived class?, a) Yes, always, b) Yes, if derived class has no constructor, c) No, programmer can’t do it, d) No, never, View Answer, Answer: d, Explanation: The constructor must be having the same name as that of a class. Hence a, constructor of one class can’t even be defined in another class. Since the constructors, can’t be defined in derived class, it can’t be overloaded too, in derived class., 3. Does constructor overloading include different return types for constructors to be, overloaded?, a) Yes, if return types are different, signature becomes different, b) Yes, because return types can differentiate two functions, c) No, return type can’t differentiate two functions, d) No, constructors doesn’t have any return type, View Answer, Answer: d, Explanation: The constructors doesn’t have any return type. When we can’t have, return type of a constructor, overloading based on the return type is not possible. Hence only, parameters can be different.
Page 53 :
4. Which among the following is possible way to overload constructor?, a) Define default constructor, 1 parameter constructor and 2 parameter constructor, b) Define default constructor, zero argument constructor and 1 parameter constructor, c) Define default constructor, and 2 other parameterized constructors with same signature, d) Define 2 default constructors, View Answer, Answer: a, Explanation: All the constructors defined in a class must have a different signature in order to, be overloaded. Here one default and other parameterized constructors are used, wherein one, is of only one parameter and other accepts two. Hence overloading is possible., 5. Which constructor will be called from the object created in the code below?, advertisement, , class A, {, int i;, A(), {, , i=0; cout<<i;, }, A(int x=0), {, i=x; cout<<I;, }, };, A obj1;, , a) Default constructor, b) Parameterized constructor, c) Compile time error, d) Run time error, View Answer, Answer: c, Explanation: When a default constructor is defined and another constructor with 1 default, value argument is defined, creating object without parameter will create ambiguity for the, compiler. The compiler won’t be able to decide which constructor should be called, hence, compile time error., 6. Which among the following is false for a constructor?, a) Constructors doesn’t have a return value, b) Constructors are always user defined, c) Constructors are overloaded with different signature, d) Constructors may or may not have any arguments being accepted, View Answer, Answer: b, Explanation: The constructors are not always user defined. The construct will be provided, implicitly from the compiler if the used doesn’t defined any constructor. The implicit
Page 54 :
constructor makes all the string values null and allocates memory space for each data, member., 7. When is the constructor called for an object?, a) As soon as overloading is required, b) As soon as class is derived, c) As soon as class is created, d) As soon as object is created, View Answer, Answer: d, Explanation: The constructor is called as soon as the object is created. The overloading, comes into picture as to identify which constructor have to be called depending on arguments, passed in the creation of object., 8. Which among the following function can be used to call default constructor implicitly in, java?, a) this(), b) that(), c) super(), d) sub(), View Answer, Answer: a, Explanation: The function this() can be used to call the default constructor from inside any, other constructor. This helps to further reuse the code and not to write the redundant data in, all the constructors., advertisement, , 9. Why do we use constructor overloading?, a) To use different types of constructors, b) Because it’s a feature provided, c) To initialize the object in different ways, d) To differentiate one constructor from another, View Answer, Answer: c, Explanation: The constructors are overloaded to initialize the objects of a class in different, ways. This allows us to initialize the object with either default values or used given values. If, data members are not initialized then program may give unexpected results., 10. If programmer have defined parameterized constructor only, then __________________, a) Default constructor will not be created by the compiler implicitly, b) Default constructor will be created by the compiler implicitly, c) Default constructor will not be created but called at runtime, d) Compile time error, View Answer, Answer: a, Explanation: When the programmer doesn’t specify any default constructor and only
Page 55 :
defines some parameterized constructor. The compiler doesn’t provide any default, constructor implicitly. This is because it is assumed that the programmer will create the, objects only with constructors., 11. Which among the following is not valid in java?, a) Constructor overloading, b) Recursive constructor call, c) Default value constructors, d) String argument constructor, View Answer, Answer: b, Explanation: Java doesn’t provide the feature to recursively call the constructor. This is to, eliminate the out of memory error in some cases that arises unexpectedly. That is an, predefined condition for constructors in java., 12. Which constructor will be called from the object obj2 in the following program?, class A, {, int i;, A(), {, i=0;, }, A(int x), {, i=x+1;, }, A(int y, int x), {, i=x+y;, }, };, A obj1(10);, A obj2(10,20);, A obj3;, , a) A(int x), b) A(int y), c) A(int y, int x), d) A(int y; int x), View Answer, Answer: c, Explanation: The two argument constructor will be called as we are passing 2 arguments to, the object while creation. The arguments will be passed together and hence compiler resolves, that two argument constructor have to be called., advertisement, , 13. What are we only create an object but don’t call any constructor for it in java?, a) Implicit constructor will be called, b) Object is initialized to some null values, c) Object is not created
Page 56 :
d) Object is created but points to null, View Answer, Answer: d, Explanation: The object becomes a reference object which can be initialized will another, object. Then this object will indirectly become another name of the object being assigned. If, not assigned, it simply points to null address., 14. Which among the following is false?, a) Constructor can’t be overloaded in Kotlin, b) Constructors can’t be called recursively in java, c) Constructors can be overloaded in C++, d) Constructors overloading depends on different signatures, View Answer, Answer: a, Explanation: Kotlin language allows constructor overloading. This is a basic feature for the, constructors. The constructor overloading allows the object to be initialized according to the, user., 15. Which is correct syntax?, a) classname objectname= new() integer;, b) classname objectname= new classname;, c) classname objectname= new classname();, d) classname objectname= new() classname();, View Answer, Answer: c, Explanation: The syntax for object creating in java with calling a constructor for is it is as in, option c. The syntax must contain the classname followed by the object name. The keyword, new must be used and then the constructor call with or without the parameters as required., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Copy Constructor, » Next - Object Oriented Programming Questions and Answers – Execution of, Constructor or Destructor, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Copy Constructor, Object Oriented Programming Questions and Answers – Execution of Constructor or, Destructor
Page 57 :
advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Event Handling, 2. Simple Java Programs, 3. Java Programming Examples on Data-Structures, 4. Java Programming Examples on String Handling, 5. C++ Questions and Answers, 6. Java Programming Examples on Arrays, 7. Java Programming Examples, 8. Java Programming Examples on Collection API, 9. Java Programming Examples on File Handling, 10. Course Registration – 2, 11. Java Programming Examples on Utility Classes, 12. Java Programming Examples on Mathematical Functions, 13. Java Programming Examples on Collections, 14. Java Programming Examples on Networking, 15. Java Programming Examples on Multithreading, 16. Java Programming Examples on Java.Lang, 17. Java Programming Examples on Exception Handling, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Execution of Constructor, or Destructor, « Prev, Next », , This set of Object Oriented Programming Questions and Answers for Experienced people, focuses on “Execution of Constructor or Destructor―., 1. Which among the following best describes the constructors?, a) A function which is called whenever an object is referenced, b) A function which is called whenever an object is created to initialize the members, c) A function which is called whenever an object is assigned to copy the values, d) A function which is called whenever an object is to be given values for members, View Answer, Answer: b, Explanation: The constructors are special type of functions which are called whenever an
Page 58 :
object is created. This is to initialize the data members of the class. The constructor allocates, memory space for all the data members., advertisement, , 2. Which among the following best describes destructor?, a) A function which is called just before the objects are destroyed, b) A function which is called after each reference to the object, c) A function which is called after termination of the program, d) A function which is called before calling any member function, View Answer, Answer: a, Explanation: The Destructors are special functions which are called just before an object is, destroyed. This functions is responsible to free all the allocated resources to the object., Objects are destroyed whenever those go out of scope., 3. Which among the following represents correct constructor?, a) ()classname, b) ~classname(), c) –classname(), d) classname(), View Answer, Answer: d, Explanation: The constructors must contain only the class name. The class name is followed, by the blank parenthesis or we can have parameters if some values are to be passed., 4. Which among the following is correct syntax for the destructors?, a) classname(), b) ()classname, c) ~classname(), d) -classname(), View Answer, Answer: c, Explanation: The destructor must have same name as that of the corresponding class. The, class name should be preceded by the tilde symbol (~)., 5. Which among the following is true?, a) First the constructor of parent classes are called in sequence of inheritance, b) First the constructor of child classes are called in the sequence of inheritance, c) First constructor called is of the object being created, d) Constructors are called randomly, View Answer, Answer: a, Explanation: First the constructor of parent class are called. The order in which the parent, class constructors are called is same in the sequence of inheritance used., advertisement
Page 59 :
6. What is the sequence of destructors call?, a) Same order as that of the constructors call, b) Random order, c) According to the priority, d) Revere of the order of constructor call, View Answer, Answer: d, Explanation: The destructors are called in the reverse order as that of the constructors being, called. This is done to ensure that all the resources are released in sequence. That is, the, derived class destructors will be called first., 7. The destructors _____________________, a) Can have maximum one argument, b) Can’t have any argument, c) Can have more than one argument, d) Can’t have more than 3 arguments, View Answer, Answer: b, Explanation: The destructors doesn’t have any arguments. The destructors have to be, called implicitly whenever an object goes out of scope. The user can’t pass argument to, the implicit call., 8. Destructor calls ________________ (C++), a) Are only implicit, b) Are only explicit, c) Can be implicit or explicit, d) Are made at end of program only, View Answer, Answer: c, Explanation: The destructors are usually called implicitly whenever an object goes out of, scope. The destructors can also be called explicitly if required. The call must be made,, implicitly or explicitly., 9. Number of destructors called are ____________, a) Always equal to number of constructors called, b) Always less than the number of constructors called, c) Always greater than the number of constructors called, d) Always less than or equal to number of constructors, View Answer, Answer: a, Explanation: Destructor will be called only to free the resources allocated for an object. The, resources are allocated only the constructor for an object is called., advertisement, , 10. For explicit call _________________, a) The destructor must be private
Page 60 :
b) The destructor must be public, c) The destructor must be protected, d) The destructor must be defined outside the class, View Answer, Answer: b, Explanation: The destructor must be public for explicit calls. If it is made private or protected, then it won’t be accessible outside the class. There is no restriction of definition the, destructor outside the class., 11. If a class have 4 constructors then it must have 4 destructors also., a) True, b) False, View Answer, Answer: b, Explanation: Even if the class have 4 constructors, only one would be used. And only one, destructor is allowed., 12. Which among the following is true for destructors?, a) Destructors can be overloaded, b) Destructors can be define more than one time, c) Destructors can’t be overloaded, d) Destructors are overloaded in derived classes, View Answer, Answer: c, Explanation: The destructors can never be overloaded. The destructors doesn’t have, arguments. And to get overloaded, they must have different signature. This is not possible if, arguments are not allowed., 13. The constructor _____________, a) Have a return type, b) May have a return type, c) Of derived classes have return type, d) Doesn’t have a return type, View Answer, Answer: d, Explanation: The constructors doesn’t have any return type. The constructors are, intended to allocate the resources for the object. Memory spaces are to be finalized., advertisement, , 14. The destructors ____________, a) Have a return type, b) May have a return type, c) Of derived classes have return type, d) Doesn’t have a return type, View Answer
Page 61 :
Answer: d, Explanation: The destructors are intended to free the memory space. And all the resources, that were allocated for the object. The return value is not supported since only memory has to, be made free., 15. The destructor can be called before the constructor if required., a) True, b) False, View Answer, Answer: b, Explanation: The destructors can be called only after the constructor calls. It is not a, mandatory rule but the deletion can only take place if there is something created using the, constructor., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Experienced people, here is, complete set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Overloading, Constructors, » Next - Object Oriented Programming Questions and Answers – Destructors, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Overloading Constructors, Object Oriented Programming Questions and Answers – Destructors, advertisement, advertisement, , Recommended Posts:, 1. Programming Questions and Answers, 2. C# Programming Examples on Strings, 3. Java Programming Examples on Mathematical Functions, 4. Ruby Programming Questions and Answers, 5. Java Programming Examples, 6. C Programming Examples on Mathematical Functions, 7. C# Questions and Answers, 8. C# Programming Examples on Functions, 9. Java Programming Examples on Utility Classes, 10. C++ Questions and Answers, 11. C# Programming Examples on Mathematics, 12. Java Programming Examples on Java.Lang, 13. Java Programming Examples on Collections
Page 62 :
14. Java Programming Examples on Exception Handling, 15. Java Programming Examples on Networking, 16. C# Programming Examples on Delegates, 17. Java Programming Examples on Multithreading, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Destructors, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on ― Destructors―., 1. Which among the following describes a destructor?, a) A special function that is called to free the resources, acquired by the object, b) A special function that is called to delete the class, c) A special function that is called anytime to delete an object, d) A special function that is called to delete all the objects of a class, View Answer, Answer: a, Explanation: It is used to free the resources that the object might had used in its lifespan. The, destructors are called implicitly whenever an object’s life ends., advertisement, , 2. When a destructor is called?, a) After the end of object life, b) Anytime in between object’s lifespan, c) At end of whole program, d) Just before the end of object life, View Answer, Answer: d, Explanation: The destructor is called just before the object go out of scope or just before its, life ends. This is done to ensure that all the resources reserved for the object are used and at, last, are made free for others., 3. Which among the following is correct for abstract class destructors?, a) It doesn’t have destructors, b) It has destructors, c) It may or may not have destructors, d) It contains an implicit destructor, View Answer
Page 63 :
Answer: a, Explanation: It doesn’t have destructors. Since an abstract class don’t have, constructors, and hence can’t have instances. Having this case, the abstract classes, don’t have destructors too, because that would be of no use here., 4. If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which, sequence are their destructors called if an object of class C was declared?, a) ~C() then ~B() then ~A(), b) ~B() then ~C() then ~A(), c) ~A() then ~B() then ~C(), d) ~C() then ~A() then ~B(), View Answer, Answer: a, Explanation: The destructors are always called in the reverse order of how the constructors, were called. Here class A constructor would have been created first if Class C object is, declared. Hence class A destructor is called at last., 5. Choose the correct sequence of destructors being called for the following code., class A{, };, class B{, };, class C: public A, public B{, , advertisement, };, , a) ~A(), ~B(), ~C(), b) ~B(), ~C(), ~A(), c) ~A(), ~C(), ~B(), d) ~C(), ~B(), ~A(), View Answer, Answer: d, Explanation: In multiple inheritance, the constructors are called in the sequence of how they, are written in inheritance sequence. And the destructors will be called in the reverse order., This can be cross verified just by printing a message from each destructor defined in classes., 6. When is the destructor of a global object called?, a) Just before end of program, b) Just after end of program, c) With the end of program, d) Anytime when object is not needed, View Answer, Answer: a, Explanation: This is because the lifespan of global object is from start of the program, till the, end of the program. And hence program end is the end of global object too. Just before the, end of program, the destructor will be called to free the acquired resources by the objects., 7. How the constructors and destructors can be differentiated?, a) Destructor have a return type but constructor doesn’t, b) Destructors can’t be defined by the programmer, but constructors can be defined
Page 64 :
c) Destructors are preceded with a tilde (~) symbol, and constructor doesn’t, d) Destructors are same as constructors in syntax, View Answer, Answer: c, Explanation: The destructors are preceded with the tilde (~) symbol. The name is same as that, of the class. These also doesn’t have any return type., 8. Destructors doesn’t accept parameters., a) True, b) False, View Answer, Answer: a, Explanation: The destructors doesn’t accept the arguments. Those are just used to free up, the resources., advertisement, , 9. Destructors can be ________, a) Abstract type, b) Virtual, c) Void, d) Any type depending on situation, View Answer, Answer: b, Explanation: The destructors can be virtual. It is actually advised to keep the destructors, virtual always. This is done to suppress the problems that may arise if inheritance is involved., 10. Global destructors execute in ___________ order after main function is terminated., a) Sequential, b) Random, c) Reverse, d) Depending on priority, View Answer, Answer: c, Explanation: The destructors are always called in reverse order no matter which destructor it, is. This is done to ensure that all the resources are able to get free. And no resource is kept, busy., 11. When is it advised to have user defined destructor?, a) When class contains some pointer to memory allocated in class, b) When a class contains static variables, c) When a class contains static functions, d) When a class is inheriting another class only, View Answer, Answer: a, Explanation: This is always advised to have user defined destructor when pointers are
Page 65 :
involved in class. This is usually done to ensure that the memory, that was allocated, dynamically, gets free after use and doesn’t cause memory leak., 12. Which among the following is correct for the destructors concept?, a) Destructors can be overloaded, b) Destructors can have only one parameter at maximum, c) Destructors are always called after object goes out of scope, d) There can be only one destructor in a class, View Answer, Answer: d, Explanation: This is so because the destructors can’t be overloaded. And the destructor, must have the same name as that of class with a tilde symbol preceding the name of the, destructor. Hence there can be only one destructor in a class. Since more than one function, with same name and signature can’t be present in same scope., 13. Which class destructor will be called first, when following code go out of scope?, class A{ };, class B{ };, class C: public B{, A a;, B b;, C c;, , advertisement, };, , a) ~A(), b) ~B(), c) ~C(), d) ~B() and ~C(), View Answer, Answer: c, Explanation: The constructor that would have created at last, its destructor will be called first, when the code goes out of scope. This will help the program to manage the resources more, efficiently., 14. When an object is passed to a function, its copy is made in the function and then, ______________, a) The destructor of the copy is called when function is returned, b) The destructor is never called in this case, c) The destructor is called but it is always implicit, d) The destructor must be user defined, View Answer, Answer: a, Explanation: When an object is passed to a function, its copy is made in the function. This, copy acts as a real object till the function is live. When the function is returned, the, copy’s destructor is called to free the resources held by it.
Page 66 :
15. What happens when an object is passed by reference?, a) Destructor is not called, b) Destructor is called at end of function, c) Destructor is called when function is out of scope, d) Destructor is called when called explicitly, View Answer, Answer: a, Explanation: The destructor is never called in this situation. The concept is that when an, object is passed by reference to the function, the constructor is not called, but only the main, object will be used. Hence no destructor will be called at end of function., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Execution of, Constructor or Destructor, » Next - Object Oriented Programming Questions and Answers – Access Specifiers, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Execution of Constructor or, Destructor, Object Oriented Programming Questions and Answers – Access Specifiers, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Arrays, 2. C# Programming Examples on Inheritance, 3. Java Programming Examples on Mathematical Functions, 4. Java Programming Examples on Collections, 5. C# Programming Examples on Events, 6. C# Programming Examples on Exceptions, 7. C# Programming Examples on LINQ, 8. C# Programming Examples on Networking, 9. C# Programming Examples on Strings, 10. C Programming Examples on Mathematical Functions, 11. C# Programming Examples on Mathematics, 12. Java Programming Examples on Utility Classes, 13. C# Programming Examples on Functions, 14. Java Programming Examples on Java.Lang, 15. Java Programming Examples on Networking
Page 67 :
16. Java Programming Examples on Exception Handling, 17. Java Programming Examples on Multithreading, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers – Object Array, advertisement, , Object Oriented Programming Questions, and Answers – Access Specifiers, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Access Specifiers―., 1. How many types of access specifiers are provided in OOP (C++)?, a) 1, b) 2, c) 3, d) 4, View Answer, Answer: c, Explanation: Only 3 types of access specifiers are available. Namely, private, protected and, public. All these three can be used according to the need of security of members., advertisement, , 2. Which among the following can be used together in a single class?, a) Only private, b) Private and Protected together, c) Private and Public together, d) All three together, View Answer, Answer: d, Explanation: All the classes can use any of the specifiers as needed. There is no restriction on, how many of them can be used together., 3. Which among the following can restrict class members to get inherited?, a) Private, b) Protected, c) Public, d) All three, View Answer
Page 68 :
Answer: a, Explanation: Private members of a class can’t be inherited. These members can only be, accessible from members of its own class only. It is used to secure the data., 4. Which access specifier is used when no access specifier is used with a member of class, (java)?, a) Private, b) Default, c) Protected, d) Public, View Answer, Answer: b, Explanation: Default access is used if the programmer doesn’t specify the specifier. This, acts in a similar way as that of private. But since nothing is specified we call it to default, access., 5. Which specifier allows a programmer to make the private members which can be, inherited?, a) Private, b) Default, c) Protected, d) Protected and default, View Answer, Answer: c, Explanation: Protected access is used to make the members private. But those members can, be inherited. This gives both security and code reuse capability to a program., advertisement, , 6. Which among the following is false?, a) Private members can be accessed using friend functions, b) Member functions can be made private, c) Default members can’t be inherited, d) Public members are accessible from other classes also, View Answer, Answer: c, Explanation: The default members can be inherited. Provided that they are in same package., It works in a little different way from private access specifier., 7. If a class has all the private members, which specifier will be used for its implicit, constructor?, a) Private, b) Public, c) Protected, d) Default, View Answer
Page 69 :
Answer: b, Explanation: The implicit constructor will always be public. Otherwise the class wouldn’t, be able to have instances. In turn, no objects will be created and the class can only be used for, inheritance., 8. If class A has add() function with protected access, and few other members in public. Then, class B inherits class A privately. Will the user will not be able to call _________ from the, object of class B., a) Any function of class A, b) The add() function of class A, c) Any member of class A, d) Private, protected and public members of class A, View Answer, Answer: d, Explanation: Class B object will not be able to call any of the private, protected and public, members of class A. It is not only about the function add(), but all the members of class A, will become private members of class B., 9. Which access specifier should be used in a class where the instances can’t be created?, a) Private default constructor, b) All private constructors, c) Only default constructor to be public, d) Only default constructor to be protected, View Answer, Answer: b, Explanation: All the constructors must be made private. This will restrict the instance of class, to be made anywhere in the program. Since the constructors are private, no instance will be, able to call them and hence won’t be allocated with any memory space., advertisement, , 10. On which specifier’s data, does the size of a class’s object depend?, a) All the data members are added, b) Only private members are added, c) Only public members are added, d) Only default data members are added, View Answer, Answer: a, Explanation: All the data members are counted to calculate the size of an object of a class., The data member access specifier doesn’t play any role here. Hence all the data size will, be added., 11. If class B inherits class A privately. And class B has a friend function. Will the friend, function be able to access the private member of class A?, a) Yes, because friend function can access all the members, b) Yes, because friend function is of class B, c) No, because friend function can only access private members of friend class
Page 70 :
d) No, because friend function can access private member of class A also, View Answer, Answer: c, Explanation: The friend function of class B will not be able to access private members of, class A. Since B is inheriting class A privately, the members will become private in class B., But private members of class A won’t be inherited at all. Hence it won’t be, accessible., 12. If an abstract class has all the private members, then _________, a) No class will be able to implement members of abstract class, b) Only single inheritance class can implement its members, c) Only other enclosing classes will be able to implement those members, d) No class will be able to access those members but can implement., View Answer, Answer: a, Explanation: The classes which inherit the abstract class, won’t be able to implement the, members of abstract class. The private members will not be inherited. This will restrict the, subclasses to implement those members., 13. Which access specifier should be used so that all the parent class members can be, inherited and accessed from outside the class?, a) Private, b) Default or public, c) Protected or private, d) Public, View Answer, Answer: d, Explanation: All the members must be of public access. So that the members can be inherited, easily. Also, the members will be available from outside the class., advertisement, , 14. Which access specifier is usually used for data members of a class?, a) Private, b) Default, c) Protected, d) Public, View Answer, Answer: a, Explanation: All the data members should be made private to ensure the highest security of, data. In special cases we can use public or protected access, but it is advised to keep the data, members private always., 15. Which specifier should be used for member functions of a class?, a) Private, b) Default, c) Protected
Page 71 :
d) Public, View Answer, Answer: d, Explanation: It is always advised that the member functions should be kept public so that, those functions can be used from out of the class. This is usually done to ensure that the, features provided by the class can be used at its maximum., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Destructors, » Next - Object Oriented Programming Questions and Answers – Private Access, Specifier, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Destructors, Object Oriented Programming Questions and Answers – Private Access Specifier, advertisement, advertisement, , Recommended Posts:, 1. Python Programming Examples on Searching and Sorting, 2. Programming Questions and Answers, 3. C# Programming Examples on Data Structures, 4. Python Programming Examples on Linked Lists, 5. C Programming Examples on Set & String Problems & Algorithms, 6. C Programming Examples on Stacks & Queues, 7. C Programming Examples on Linked List, 8. C++ Programming Examples on Data-Structures, 9. Python Programming Examples on Stacks & Queues, 10. Java Programming Examples on Data-Structures, 11. Java Programming Examples on Multithreading, 12. C Programming Examples on Data-Structures, 13. Java Programming Examples on Collection API, 14. Java Programming Examples on Collections, 15. C++ Programming Examples on STL, 16. Java Programming Examples on Java.Lang, 17. C# Basic Programming Examples, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Constructors
Page 72 :
advertisement, , Object Oriented Programming Questions, and Answers – Private Access Specifier, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Private Access Specifier―., 1. If a function has to be called only by using other member functions of the class, what, should be the access specifier used for that function?, a) Private, b) Protected, c) Public, d) Default, View Answer, Answer: a, Explanation: The function should be made private. In this way, the function will be available, to be called only from the class member functions. Hence the function will be secure from the, outside world., advertisement, , 2. Which among the following is correct for the code given below?, class student, {, private: student(), {, }, public : student( int x), {, marks =x;, }, };, , a) The object can never be created, b) The object can be created without parameters, c) Only the object with only 1 parameter can be created, d) Only the object with some parameters can be created, View Answer, Answer: c, Explanation: For creating object without parameters, the default constructor must be defined, in public access. But here, only parameterized constructor is public, hence the objects being, created with only one parameter will only be allowed., 3. Which among the following is true for the code given below?
Page 73 :
class A, {, private : int marks; char name[20];, public :, A(int x=100), {, marks=x;, }, };, , a) Objects can be created with one parameter or without parameter, b) Object can be created only with one parameter, c) Object can be created with more than one parameter, d) Objects can be create only without parameter, View Answer, Answer: a, Explanation: The constructor here has a default argument constructor. Hence we can pass one, parameter, but that is optional. If an object is created without parameter, the default value will, be used in the constructor definition., advertisement, , 4. Which among the following is correct to call a private member from outside the class?, a) object.memberfunction( parameters );, b) object->memberfunction( parameters );, c) object->memberfunction( parameteres); or object.memberfunction( parameters );, d) Not possible, View Answer, Answer: d, Explanation: The private member function will not be accessible from outside the class., Hence any syntax will not work to access the private members. If you have the address of the, member, may be you can access those members, but that is a totally different case and, concept., 5. If private members have to be accessed directly from outside the class but the access, specifier must not be changed, what should be done?, a) Specifier must be changed, b) Friend function should be used, c) Other public members should be used, d) It is not possible, View Answer, Answer: b, Explanation: For calling the function directly, we can’t use another function because that, will be indirect call. Using friend function, we can access the private members directly., 6. Which access specifier is/are most secure during inheritance?, a) Private, b) Default, c) Protected
Page 74 :
d) Private and default, View Answer, Answer: a, Explanation: The private members are most secure in inheritance. The default members can, still be in inherited in special cases, but the private members can’t be accessed in any, case., 7. Choose the correct option for the code given below., class A{ static int c=0; public: A(){ c++; } };, a) Constructor will make c=1 for each object created, b) Constructor will make c=0 for each object created, c) Constructor will keep number of objects created, d) Constructor will just initialize c=0 then increment by 1, View Answer, Answer: c, Explanation: The constructor is using a static member to keep the count of the number of, objects created. This is done because the variable c is static and hence the value will be, common for all the objects created., 8. Which option is false for the following code?, class A, {, private : int sum(int x, int y), {, return x+y;, }, public: A(), {, }, A(int x, int y), {, cout<<sum(x,y);, }, };, , a) Constructor can be created with zero argument, b) Constructor prints sum, if two parameters are passed with object creation, c) Constructor will give error if float values are passed, d) Constructor will take 0 as default value of parameters if not passed, View Answer, Answer: d, Explanation: Constructor is not having any default arguments hence no default value will be, given to any parameters. Only integer values must be passed to the constructor if we need the, sum as output, otherwise if float values are passed, type mismatch will be shown as error., advertisement, , 9. Which member will never be used from the following class?, class A()
Page 75 :
{, int marks; char name[20];, public : A(), {, marks=100;, }, void disp(), {, cout<<―Marks= ―<'<marks;, cout<<―Student―;, }, };, , a) name variable will never be used, b) marks variable will never be used, c) constructor will never be used, d) disp() function will never be used, View Answer, Answer: a, Explanation: Variable name will never be used. It is a private member. None other than class, members can access name, also, neither the constructor nor the disp() function are accessing, the variable name. Hence it will never be accessible., 10. Private member functions can be overloaded., a) True, b) False, View Answer, Answer: a, Explanation: The private functions can also be overloaded. This can be done in usual way by, having the same name of the member function and having different signature. Only thing is,, they must be accessed from members of class only., 11. Which among the following is true?, a) Private member functions can’t be overloaded, b) Private member functions can be overridden, c) Private member functions can’t be overloaded with a public member, d) Private member function can’t be overridden, View Answer, Answer: d, Explanation: The private member functions can be overloaded but they can’t be, overridden. This is because, overriding means a function with same name in derived class,, gets more priority when called from object of derived class. Here, the member function is, private so there is no way that it can be overridden., 12. Which data member in following code will be used whenever an object is created?, Class A, {, int x; int y; int z;, public : A()
Page 76 :
{, y=100; x=100*y;, }, };, , a) x will be used, b) y will be used, c) z will be used, d) All will be used, View Answer, Answer: c, Explanation: Whenever an object will be created, the constructor will be called. Inside, constructor we are using the data members x and y. Hence these two will always be used with, each object creation., advertisement, , 13. Which member can be considered most secure in the code below?, class A(), {, int a;, private : int b;, protected : int c;, public : int d;, };, , a) a, b) b, c) c, d) d, View Answer, Answer: b, Explanation: The default variables can be inherited in some special cases but the public, members can never be inherited. Hence the most secure data member in the class is b., 14. Which among the following is correct for the code given below?, class A, {, private : A(), {, }, public : A(int x), {, }, };, A a;, A b(100);, , a) Program will give compile time error, b) Program will run fine, c) Program will give runtime error
Page 77 :
d) Program will give logical error, View Answer, Answer: a, Explanation: The program will be giving a compile time error as the default constructor is, private in class. And, the logical errors are usually runtime so we can’t say that the, program will give logical error. The program will not run., 15. Which among the following is correct?, a) Private specifier must be used before public specifier, b) Private specifier must be used before protected specifier, c) Private specifier must be used first, d) Private specifier can be used anywhere in class, View Answer, Answer: d, Explanation: The private specifier can be used anywhere in the class as required. It is not a, rule to mention the private members first and then others. It is just followed to write first for, better readability., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Access Specifiers, » Next - Object Oriented Programming Questions and Answers – Protected Access, Specifier, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Access Specifiers, Object Oriented Programming Questions and Answers – Protected Access Specifier, advertisement, advertisement, , Recommended Posts:, 1., 2., 3., 4., 5., 6., 7., 8., , C# Programming Examples on Files, C Programming Examples on Linked List, C Programming Examples on Mathematical Functions, Java Programming Examples on Networking, C# Programming Examples on Threads, Ruby Programming Questions and Answers, Programming Questions and Answers, C# Programming Examples on Mathematics
Page 78 :
9. Java Programming Examples on Utility Classes, 10. Java Programming Examples, 11. C# Programming Examples on Exceptions, 12. Java Programming Examples on File Handling, 13. C# Programming Examples on Functions, 14. Java Programming Examples on Multithreading, 15. C# Basic Programming Examples, 16. Java Programming Examples on Collections, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Protected Access Specifier, « Prev, Next », , This set of Object Oriented Programming Question Bank focuses on “Protected Access, Specifier―., 1. Which among the following best describes the protected specifier?, a) Members are most secure and can’t be used outside class, b) Members are secure but can be used outside the class, c) Members are secure as private, but can be inherited, d) Members are secure like private, but can’t be inherited, View Answer, Answer: c, Explanation: The members which are made protected, are most secure if inheritance is not, used. But, this facility is provided to keep those members private and with that, they can be, inherited by other classes. This is done to make the code more flexible., advertisement, , 2. If a constructor is defined in protected access, then?, a) It’s instance can be created inside the subclasses, b) It’s instance can be created anywhere in the program, c) It’s instance can be created inside the subclasses and main() function, d) It’s instance can be created inside the parent class only, View Answer, Answer: a, Explanation: The instances will be allowed to be created only inside the sub classes. This is, because the protected members will be inherited and hence the constructor too. This will, allow the subclasses to call the constructor whenever an object is created.
Page 79 :
3. For the following code, choose the correct option., class A, {, int marks;, protected : A(), {, marks=100;, }, public : A( int x), {, marks=x;, }, };, , a) The instances can be created only in subclasses, b) The instances can be created only in main() function, c) The instances can be created only in parent class, d) The instances can be created anywhere in the program, View Answer, Answer: d, Explanation: The instances can be created anywhere in the program. The only restriction will, be on which constructor will have to be called. The instances with zero arguments will be, allowed to be created only inside the subclasses, but the instances with one argument can be, created anywhere in the program., 4. If the protected members are to be made accessible only to the nearest subclass and no, further subclasses, which access specifier should be used in inheritance?, a) The sub class should inherit the parent class privately, b) The sub class should inherit the parent class as protected, c) The sub class should inherit the parent class as public, d) The sub class can use any access modifier, View Answer, Answer: a, Explanation: The sub class should use private inheritance. This will allow only the nearest, sub classes to inherit the protected members and then those members will become private., Hence further inheritance of those members will not be possible., 5. What will be the output of the following code (all header files and required things are, included)?, advertisement, , class A, {, int marks;, protected : A(int x), {, marks=x;, }, public : A(), {, marks=100;
Page 80 :
}, }, class B, {, A a;, A b=100;, };, main(), {, A a, b=100;, B c;, }, , a) Program runs fine, b) Program gives runtime error, c) Program gives compile time error, d) Program gives logical error, View Answer, Answer: c, Explanation: The objects being created with assignment value are allowed, if the constructor, accepts only 1 argument. But main() function will not be able to create the object here with, assignment, as the constructor which accepts one argument is in protected mode in the class., 6. Which among the following is true for the given code below?, class A, {, protected : int marks;, public :, A(), {, marks=100;, }, disp(), {, cout<<―marks=―<<marks;, }, };, class B: protected A, {, };, B b;, b.disp();, , a) Object b can’t access disp() function, b) Object b can access disp() function inside its body, c) Object b can’t access members of class A, d) Program runs fine, View Answer, Answer: a, Explanation: The object of class B can’t access the members of A outside the class. This, is because the class is being inherited in protected access, so all the members will become, protected in subclass B.
Page 81 :
7. Protected members differ from default members as _______, a) Protected members can be accessed outside package using inheritance, but default, can’t, b) Default members can be accessed outside package using inheritance, but protected, can’t, c) Protected members are allowed for inheritance but Default members are not allowed, d) Both are same, View Answer, Answer: a, Explanation: The protected members are allowed in the same package but can also be, accessed in other packages using inheritance. But the default members can never be, accessible in other packages., 8. If all the members are defined in protected specifier then? (Constructors not considered), a) Instance of class can’t be created, b) Instance of class can be created anywhere, c) Instance of class can be created only in subclasses, d) Instance of class can be created only in main() function, View Answer, Answer: b, Explanation: The instances can be created anywhere in the program. This is because the, constructors are not considered among the members defined in protected mode. Hence the, default implicit constructor will be used whenever an object is created., advertisement, , 9. Which among the following is correct for the code given?, class A, {, private: int marks;, A(), {, }, Public : disp(), {, cout<< marks;, }, };, class B: public A, {, }, B b;, , a) Instance of B will not be created, b) Instance of B will be created, c) Program gives compile time error, d) Program gives runtime error, View Answer, Answer: a, Explanation: Instance of B will not be created. When you try to create an instance of B, First
Page 82 :
the constructor of parent class will be called, but the parent class constructor is private, hence, it won’t be able to initialize and allocate memory for parent class members. In turn, the, object of B will not be created., 10. If protected inheritance is used then _____, a) Public members become public in subclass, b) Protected members become public in subclass, c) Protected members become protected in subclass, d) Protected and Public members become protected in subclass, View Answer, Answer: d, Explanation: The protected and public members of the parent class will become the protected, members in subclass. This is predefined rule of inheritance. The reason behind is to maintain, the level of security in subclass too., 11. If protected members are to be accessed from outside the class then__________, a) Members must be inherited publicly in subclass, b) Members must accessed using class pointers, c) Members must be accessed as usual, d) Members must be made public, View Answer, Answer: d, Explanation: The members must be made public, otherwise it is not possible. In every case,, the protected members will act as private members if it’s about access specifier. It will, only be inherited, that too will lead to make those members protected again, in subclasses., 12. Which among the following can use protected access specifier?, a) Members which may be used in other packages, b) Members which have to be secure and should be used by other packages/subclass, c) Members which have to be accessed from anywhere in the program, d) Members which have to be as secure as private but can be used by main() function, View Answer, Answer: b, Explanation: The members which have to be secure and might get used in other packages or, subclasses can use protected access. This also allows the members to be safe from accidental, modification., 13. Protected access is same as default access that is given implicitly in java if no specifier is, mentioned., a) True, b) False, View Answer, Answer: b, Explanation: The statement given is true. The clear difference is protected members are, available in other packages also, but the default members are available within the package, only.
Page 83 :
14. If a class have default constructor defined in private access, and one parameter, constructor in protected mode, how will it be possible to create instance of object?, a) Define a constructor in public access with different signature, b) Directly create the object in the subclass, c) Directly create the object in main() function, d) Not possible, View Answer, Answer: a, Explanation: If a new constructor is defined in public access. That will be available to the, whole program. Only restriction will be of the way to use it., advertisement, , 15. What will be the output of the program given below?, class A, {, Public : A(int a=0), {, cout<<―new A―;, }, };, A a;, A b;, A c;, , a) new A new A new A, b) newAnewAnewA, c) new Anew Anew A, d) new A new Anew A, View Answer, Answer: c, Explanation: The constructor has a default argument. Whenever the object is created, the, constructor will be called and print the message in its definition. Since the argument is default, valued, it is not mandatory to pass anything to the new object., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice Object Oriented Programming Question Bank, here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Private Access, Specifier, » Next - Object Oriented Programming Questions and Answers – Public Access Specifier, Categories Object Oriented Programming MCQs Post navigation
Page 84 :
Object Oriented Programming Questions and Answers – Private Access Specifier, Object Oriented Programming Questions and Answers – Public Access Specifier, advertisement, advertisement, , Recommended Posts:, 1. Python Programming Examples on Trees, 2. Java Programming Examples on Utility Classes, 3. Java Programming Examples on Arrays, 4. C# Programming Examples on Data Structures, 5. C# Programming Examples on Mathematics, 6. C# Programming Examples on Files, 7. Java Programming Examples on Event Handling, 8. Java Programming Examples on File Handling, 9. C# Programming Examples, 10. C# Programming Examples on Exceptions, 11. Java Programming Examples on Multithreading, 12. C# Basic Programming Examples, 13. Java Programming Examples, 14. C# Programming Examples on Functions, 15. Java Programming Examples on Collections, 16. Java Programming Examples on Java.Lang, 17. C# Programming Examples on Inheritance, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Public Access Specifier, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Public Access Specifier―., 1. Which among the following is true for the code given below?, class A, {, , advertisement, int marks;, public : disp(), {, cout<<marks;, }, , }
Page 85 :
class B: protected A, {, char name[20];, }, A a; a.disp();, B b; b.disp();, , a) Only object of class A can access disp() function, b) Only object of class B can access disp() function, c) Both instances can access disp() function, d) Accessing disp() outside class is not possible, View Answer, Answer: a, Explanation: The object of class A can access the disp() function. This is because the disp(), function is public in definition of class A. But it can’t be accessed from instance of class, B because the disp() function is protected in class B, since it was inherited as protected., 2. If the members have to be accessed from anywhere in the program and other packages, also, which access specifier should be used?, a) Public, b) Private, c) Protected, d) Default, View Answer, Answer: a, Explanation: The access specifier must be public so as to access the members outside the, class and anywhere within the program without using inheritance. This is a rule, predefined, for the public members., 3. Which among the following have least security according to the access permissions, allowed?, a) Private, b) Default, c) Protected, d) Public, View Answer, Answer: d, Explanation: The public members are available to the whole program. This makes the, members most vulnerable to accidental changes, which may result in unwanted modification, and hence unstable programming., advertisement, , 4. Which among the following can be used for outermost class access specifier in java?, a) Private, b) Public, c) Default, d) Default or Public, View Answer
Page 86 :
Answer: d, Explanation: Either default or public access specifier must be used for outermost classes., Private can be used with inner classes. This is done so that all the members can access and, use the utmost class and that program execution can be done from anywhere. Inner classes, can be made private for security., 5. We can reduce the visibility of inherited methods., a) True, b) False, View Answer, Answer: b, Explanation: The statement given is false. This is because when we inherit the members they, can either be made more secure or be at same access. But the visibility reduction is not, possible, for example, if a member is protected in parent class, then it can only be made, protected or private in subclass and not public in any case., 6. If members of a super class are public, then________, a) All those will be available in subclasses, b) None of those will be available in subclasses, c) Only data members will be available in subclass, d) Only member functions will be available in subclass, View Answer, Answer: a, Explanation: All the members will be available in subclasses. Though it is not guaranteed, whether the members will be available in subsequent subclasses from the first subclass., 7. How many public class(s) (outermost) can be there in a java program?, a) 1, b) 2, c) 3, d) As required, View Answer, Answer: a, Explanation: There can be only one public class in a java program. The public class name, must match the name of file. And there can’t be more than one class with same name in a, single program in same scope. Hence it is not possible to have more than one public class in, java program., 8. What is the output of the following code?, advertisement, package pack1;, class A, {, public A(), {, System.out.print(“object created―);, }, }
Page 87 :
package pack2;, import pack1.*;, class B, {, A a=new A();, }, , a) Output is: object created, b) Output is: object createdobject created, c) Compile time error, d) Run time error, View Answer, Answer: c, Explanation: The program will give compile time error. Class A is defined with default, access specifier. This directly means that class A will be available within package only. Even, if the constructor is public, the object will not be created., 9. Which among the following for public specifier is false?, a) The static members can’t be public, b) The public members are available in other packages too, c) The subclasses can inherit the public members privately, d) There can be only one public class in java program, View Answer, Answer: a, Explanation: The static members are not property of any object of the class. Instead, those are, treated as property of class. This allows us to have public static members too., 10. A class has its default constructor defined as public. Class B inherits class A privately., The class ___________, a) B will not be able to have instances, b) Only A can have instances, c) Only B can have instances, d) Both classes can have instances, View Answer, Answer: d, Explanation: Class A can have instances as it has public default constructor. Class will have, its own constructors defined. Hence both classes can have instances., 11. Which specifier can be used to inherit protected members as protected in subclass but, public as public in subclass?, a) Private, b) Default, c) Public, d) Protected, View Answer, Answer: c, Explanation: The specifier that can make protected member’s protected in subclass and
Page 88 :
public member’s public in subclass, is public. This is done to maintain the security level, of protected members of parent class., advertisement, , 12. Which among the following is true for public class?, a) There can be more than one public class in a single program, b) Public class members can be used without using instance of class, c) Public class is available only within the package, d) Public classes can be accessed from any other class using instance, View Answer, Answer: d, Explanation: The public class is a usual class. There is no special rule but the members of the, class can be accessed from other classes using instance of the class. This is usually useful to, define main() function., 13. If a class doesn’t have public members, then________, a) None of its members will be able to get inherited, b) None of its instance creation will be allowed, c) None of its member function can be called outside the class, d) None of its data members will be able to get initial value, View Answer, Answer: c, Explanation: According to rule of private, protected and default access specifiers, none of the, members under these specifiers will be able to get invoked outside the class. We are not sure, about the members of class specifically so other options doesn’t give a fixed answer., 14. In multi-level inheritance(all public), the public members of parent/superclass will, ________, a) Will continue to get inherited subsequently, b) Will not be inherited after one subclass inheritance, c) Will not be available to be called outside class, d) Will not be able to allocated with any memory space, View Answer, Answer: a, Explanation: The public inheritance makes the public members of the base class, public in, derived classes. This can be used when the same feature have to be redefined with each new, class inheriting the base class., 15. Which specifier allows to secure the public members of base class in inherited classes?, a) Private, b) Protected, c) Public, d) Private and Protected, View Answer, Answer: d, Explanation: Both the private and protected specifiers can make the public members of the
Page 89 :
base class more secure. This is useful if we stop using the parent class members and use the, classes which inherited the parent class, so as to secure data better., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Protected Access, Specifier, » Next - Object Oriented Programming Questions and Answers – Data Members, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Protected Access Specifier, Object Oriented Programming Questions and Answers – Data Members, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples on Mathematical Functions, 2. Java Programming Examples on String Handling, 3. C# Programming Examples on Files, 4. Java Programming Examples on File Handling, 5. C++ Programming Examples on STL, 6. Java Programming Examples on Utility Classes, 7. Java Programming Examples on Event Handling, 8. Java Programming Examples, 9. Java Programming Examples on Collection API, 10. Java Programming Examples on Multithreading, 11. Java Programming Examples on Networking, 12. C# Programming Examples on Exceptions, 13. C# Programming Examples on Inheritance, 14. C# Basic Programming Examples, 15. C# Programming Examples on Functions, 16. Java Programming Examples on Collections, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement
Page 90 :
Object Oriented Programming Questions, and Answers – Data Members, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Data Members―., 1. What is the term used to indicate the variable and constants of a class?, a) Data members, b) Variables of class, c) Data characters, d) Constants, View Answer, Answer: a, Explanation: The variables inside a class are termed data members of the class. It is not a, mandatory rule but variables are used to refer to usual variables used in functions or globally., The term is given because the values stored in those variables represent some kind of data, related to class., advertisement, , 2. Data members ________________ (C++), a) Can be initialized with declaration in classes, b) Can be initialized only with help of constructors, c) Can be initialized either in declaration or by constructor, d) Can’t be initialized, View Answer, Answer: b, Explanation: The data members are not property of class, those are property of the instances, of the class. And the memory for the data members are not reserved until a constructor is, called. Hence we use constructors for their initialization after the memory is reserved., 3. Which among the following is true for data members?, a) Private data members can be initialized with declaration in class, b) Static members are initialized in constructors, c) Protected data members can be initialized in class directly, d) Static data members are defined outside class, not in constructor, View Answer, Answer: d, Explanation: Static members are not property of instances of classes. Those are shared by all, the object of classes. Hence those are defined outside the constructor, so as to make them, common for all the objects.
Page 91 :
4. What should be done for data member to be of user defined structure type?, a) The structure must have been defined before class., b) The structure must have been defined after the class definition, c) The structure must be predefined, d) The structure type data members can’t be used, View Answer, Answer: a, Explanation: The structure must have been defined prior to its use. If the structure is not, defined, then the memory space will not be allocated for its members. This leads to undefined, use of new data types., 5. How many data members can a class contain?, a) 27, b) 255, c) 1024, d) As many as required, View Answer, Answer: d, Explanation: Any class can have as many data members as required. The only restriction that, may arise is when there is not enough memory space. This gives flexibility to define a class, with best properties possible., advertisement, , 6. How to access data members of a class?, a) Dot operator, b) Arrow operator, c) Dot or arrow as required, d) Dot, arrow or direct call, View Answer, Answer: c, Explanation: The data members can never be called directly. Dot operator is used to access, the members with help of object of class. Arrow is usually used if pointers are used., 7. To create a pointer to a private data member of a class, outside the class, which among the, following is correct?, a) Return the address of the private data member using a member function, b) Access the private member using a pointer outside class, c) Declare the member as pointer inside the class, d) Not possible to create pointer to a private member, View Answer, Answer: a, Explanation: We can call a public member function and return the address of any private data, member. Though the pointer being returned must be defined inside class itself. And the, returned address can be stored in a pointer.
Page 92 :
8. Which among the following is true for use of setter() and getter() function?, a) Considered best for manipulating data values, b) Considered the only proper way to manipulate the values, c) Considered specially for private members manipulation, d) Considered a red flag, and not recommended for large scale use, View Answer, Answer: d, Explanation: This concept of getter and setter functions is not acceptable if used too much., This is considered to be inappropriate in OOP perspective. Though it is commonly used, it, doesn’t work according to OOP concepts at some higher level of understanding., 9. What is the output of following code?, int n=10;, // global, class A(), {, private : int n;, public : int m;, A(), {, n=100; m=50;, }, void disp(), {, cout<<―n―<<m<<n;, };, , a) 1050100, b) 1005010, c) n5010, d) n50100, View Answer, Answer: d, Explanation: In cout we have specified n as a string to be printed. And m is a variable so its, value gets printed. And global variable will not be used since local variable have more, preference., advertisement, , 10. The static member functions can only use ________, a) Static data members, b) Private data members, c) Protected data members, d) Constant data members, View Answer, Answer: a, Explanation: The static member functions can only access static data members. This is, because the static member function can’t work with the properties that change object to, object. It is mandatory that only the common properties of all the objects be used. And only, static data members are common to all as those are property of class.
Page 93 :
11. A class can have self-referential data members., a) True, b) False, View Answer, Answer: b, Explanation: The data members in a class can never refer to own class type. This is not, possible because the data members should have some memory allocated for its object before, the self-reference is used, but class must call constructor for that. Hence not possible., 12. What is the keyword used to make data members have same value?, a) static, b) const, c) double, d) abstract, View Answer, Answer: b, Explanation: The keyword const can be used anywhere to make the variable have same value, all the time. This restriction is made to use the same value whenever required. Also, this can, restrict accidental changes., 13. Which data members can be inherited but are private to a class?, a) Private, b) Protected, c) Protected and Static, d) Privately inherited, View Answer, Answer: b, Explanation: Static members inheritance also depends on the type of specifier they have., Only the protected members can be inherited but remain private to class. If static members, are defined in private access, they won’t be allowed for inheritance., advertisement, , 14. The arguments passed to member functions by reference are considered as data members, of class., a) True, b) False, View Answer, Answer: b, Explanation: This is a wrong statement. As only the data defined inside class is considered as, its member. But even if a variable is passed by reference it would be the same variable that is, outside the class. Hence it can’t be considered class member., 15. Which among the following is not allowed for data member declaration?, a) int a;, b) static int a;, c) abstract a;
Page 94 :
d) Boolean a;, View Answer, Answer: c, Explanation: The abstract keyword in the declaration of data members is not allowed. This is, because the abstract keyword features can’t be used with the data members of the class., We can have all other syntax given, but not abstract., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Public Access Specifier, » Next - Object Oriented Programming Questions and Answers – Member Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Public Access Specifier, Object Oriented Programming Questions and Answers – Member Functions, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Multithreading, 2. Java Programming Examples, 3. C# Programming Examples on Functions, 4. Ruby Programming Questions and Answers, 5. C Programming Examples on File Handling, 6. Data Structure Questions and Answers, 7. C# Programming Examples on Files, 8. C Tutorials, 9. Data Science Questions and Answers, 10. Python Programming Examples on Linked Lists, 11. C Programming Examples on Stacks & Queues, 12. C Programming Examples on Linked List, 13. Java Programming Examples on Java.Lang, 14. C++ Programming Examples on Data-Structures, 15. C# Programming Examples on Data Structures, 16. Java Programming Examples on Classes, 17. C Programming Examples on Data-Structures, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Data-Structures, 20. Object Oriented Programming Questions and Answers
Page 95 :
advertisement, , Object Oriented Programming Questions, and Answers – Member Functions, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Member Functions―., 1. Which among the following best describes member functions?, a) Functions which are defined within the class, b) Functions belonging a class, c) Functions in public access of a class, d) Functions which are private to class, View Answer, Answer: b, Explanation: We can’t say that only functions that are defined inside class are member, functions. There can be some inherited functions. Though they doesn’t belong to the class, but are property of the objects once inheritance is used. So the nearest definition is functions, belonging to a class., advertisement, , 2. How many types of member functions are generally there in C++?, a) 2, b) 3, c) 4, d) 5, View Answer, Answer: d, Explanation: There are 5 types of member functions that are generally provided in C++., Namely, simple, static, const, inline and friend member functions. Member functions are, specific to classes., 3. How can a static member function be called in the main function?, a) Using dot operator, b) Using arrow operator, c) Using dot or arrow operator, d) Using dot, arrow or using scope resolution operator with class name, View Answer, Answer: d, Explanation: The member functions can be called using only the dot operator or the arrow, operator. But the static members can be called using directly the class name followed by the, scope resolution operator and static member function name. This is useful when you, don’t have any object to call the member.
Page 96 :
4. What are inline member functions?, a) Member functions which can be called without object, b) Member functions whose definition is expanded in place of its call, c) Member functions whose definition is faster than simple function, d) Member function which is defined in single line, View Answer, Answer: b, Explanation: The member functions whose definition is expanded at the call, and no jump to, function and return happened, are termed as inline functions. This is used to make the, program faster and more efficient., 5. What happens if non static members are used in static member function?, a) Compile time error, b) Runtime error, c) Executes fine, d) Executes if that member function is not used, View Answer, Answer: a, Explanation: There must be specific memory space allocated for the data members before the, static member functions uses them. But the space is not reserved if object is not declared., Hence only if static members are not used, it leads to compile time error., advertisement, , 6. Static member functions _____________, a) Contains “this― pointer for data members, b) Contains “this― pointer if used for member functions, c) Doesn’t contain “this― pointer, d) Doesn’t contain “this― pointer if member functions are referred, View Answer, Answer: c, Explanation: The static member functions doesn’t contain “this― pointer. Static, member functions can’t be defined as const or volatile also. These are restrictions on, static member functions., 7. How to access members of the class inside a member function?, a) Using this pointer only, b) Using dot operator, c) Using arrow operator, d) Used directly or with this pointer, View Answer, Answer: d, Explanation: The members of a class can be used directly inside a member function. We can, use this pointer when there is a conflict between data members of class and arguments/local, function variable names.
Page 97 :
8. For overloading “( )―, “[ ]― or “->― operators, a class __________, a) Must use static member functions, b) Must use non-static member functions, c) Must be non-static member and should not be friend of class, d) Must use static member function or a friend member function, View Answer, Answer: c, Explanation: For overloading those operators for a class, the class must use non-static, member function so that doesn’t remain common to all the objects, and each object can, use it independently. The friend functions is also restricted so as to keep the security of data., 9. If a virtual member function is defined ___________, a) It should not contain any body and defined by subclasses, b) It must contain body and overridden by subclasses, c) It must contain body and be overloaded, d) It must not contain any body and should not be derived, View Answer, Answer: a, Explanation: The virtual functions are defined using virtual keyword. These are made in, order to make all the classes to define them as the class gets inherited. Increases code, understanding., 10. Member functions of a generic class are _____________, a) Not generic, b) Automatically generic, c) To be made generic explicitly, d) Given default type as double, View Answer, Answer: b, Explanation: When generic type is used in a class, the functions are automatically generic., This is so because the functions would use the same type as defined to make the class, generic. The functions will get to know the type of data as soon as the generic class is used., It’s inbuilt feature., advertisement, , 11. Member function of a class can ____________, a) Access all the members of the class, b) Access only Public members of the class, c) Access only the private members of the class, d) Access subclass members, View Answer, Answer: a, Explanation: The member functions has access to all the members of the class. Whenever, data members of a class, which might be private, have to be modified, we make use of these, member functions. This is more secure way to manipulate data.
Page 98 :
12. Which among the following is proper syntax for class given below?, class A, {, int a,b;, public : void disp();, }, , a) void disp::A(){ }, b) void A::disp(){ }, c) void A:disp() { cout<<a<<b ; }, d) void disp:A(){ cout<<a<<b; }, View Answer, Answer: b, Explanation: The syntax in option void A::disp(){ } is correct. We use scope resolution to, represent the member function of a class and to write its definition. It is not necessary for a, function to have anything in its definition., 13. A member function can _______________ of the same class., a) Call other member functions, b) Call only private member functions, c) Call only static member functions, d) Call only const member functions, View Answer, Answer: a, Explanation: We can call one function inside another function to access some data of class. A, public member function can be used to call a private member function which directly, manipulates the private data of class., advertisement, , 14. Which member function doesn’t require any return type?, a) Static, b) Constructor, c) Const, d) Constructor and destructor, View Answer, Answer: d, Explanation: All the member functions work same as normal functions with syntax. But the, constructor and destructor are also considered as member functions of a class, and they never, have any data type., 15. Which among the following is not possible for member function?, a) Access protected members of parent class, b) Definition without return type, c) Access public members of subclass, d) Access static members of class, View Answer
Page 99 :
Answer: c, Explanation: A member function of a class can only have the access to the members of its, own class and parent classes if inheritance used. Otherwise a member function can never, access the members of a subclass. Accessing static members of a class is possible by normal, and static member functions., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Data Members, » Next - Object Oriented Programming Questions and Answers – Local Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Data Members, Object Oriented Programming Questions and Answers – Local Class, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on String Handling, 2. C Tutorials, 3. C Programming Examples on Stacks & Queues, 4. Python Programming Examples on Linked Lists, 5. C++ Questions and Answers, 6. C# Basic Programming Examples, 7. Java Programming Examples, 8. C Programming Examples on Linked List, 9. Java Programming Examples on Collections, 10. Ruby Programming Questions and Answers, 11. Java Programming Examples on File Handling, 12. Java Programming Examples on Multithreading, 13. Java Programming Examples on Java.Lang, 14. C Programming Examples on Mathematical Functions, 15. C# Programming Examples on Delegates, 16. Java Programming Examples on Mathematical Functions, 17. Java Programming Examples on Inheritance, 18. Java Programming Examples on Classes, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers, advertisement
Page 100 :
Object Oriented Programming Questions, and Answers – Local Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Local Class―., 1. What are local classes?, a) Classes declared inside a package, b) Classes declared inside a function, c) Classes declared inside a class, d) Classes declared inside structure, View Answer, Answer: b, Explanation: The classes declared inside a package are available to all the functions and, classes, hence can’t be called local. This is somewhat similar concept that we use to, denote variables of a function. The classes declared inside functions will be local to them., advertisement, , 2. All member functions of a local class must be ___________, a) Defined outside class body, b) Defined outside the function definition, c) Defined inside the class body, d) Defined at starting of program, View Answer, Answer: c, Explanation: There is a restriction on where the member functions of the local class should be, define. Those must be defined inside the class body only. This is to reduce the ambiguity and, complexity of program., 3. Can local class members access/use the general local variables (except static, abstract etc.), of the function in which it is defined?, a) Yes, it can access with arrow operator, b) No, it can’t access with dot operator, c) Yes, it can access using dot operator, d) No, it can’t access In anyway, View Answer, Answer: d, Explanation: The local variables of the functions are not available to the member functions of, the class. This is done to reduce the ambiguity in variables and their access rules., 4. Which type of data can a local class access from the function in which it is defined?, a) Static and extern
Page 101 :
b) Abstract and static, c) Void and extern, d) Const and static, View Answer, Answer: a, Explanation: The local classes have this feature to access the static and extern variables of the, function in which those are defined. This feature is available since these type of data are, common to the program and is created only one time. Run time creation and destruction of, these variables is not done. The only restriction that may apply is those members must be, constants., 5. Local classes can access the type names and enumerators defined by the enclosing, function., a) True, b) False, View Answer, Answer: a, Explanation: This is a little tricky part with local classes. Though the local class can’t, access the general variables of the function but can access the types that are defined inside the, function. This is because the whole definition of that type would be existing inside the class., advertisement, , 6. Can static variables be declared inside a local class?, a) Yes, with public access specifier, b) Yes, anywhere as required, c) No, not possible in private access specifier, d) No, not possible anyway, View Answer, Answer: d, Explanation: No, the static variables can’t be declared inside a local class. This is because, each time the function is called, all the variables get created again and are destroyed as soon, as the function is returned. This would have been possible id the static variable was of, function., 7. All the member functions of local classes are __________ by default., a) Static, b) Inline, c) Abstract, d) Virtual, View Answer, Answer: c, Explanation: All the members are defined inside the class body. And when the member, functions are defined inside the class body, they are made inline by default. If the definition is, too complex, those are made normal functions.
Page 102 :
8. The enclosing function has no special access to the members of the local class., a) True, b) False, View Answer, Answer: a, Explanation: This is a rule that the enclosing function doesn’t have any special access to, the members of the local class. This is done to maintain the security of class members. And to, adhere to the rules of OOP., 9. Which language can use inheritance with local classes?, a) Kotlin, b) Java, c) SmallTalk, d) SAP ABAP, View Answer, Answer: d, Explanation: Other language might support inheritance with local classes but those, doesn’t provide all the proper features of inheritance. Language SAP ABAP provides a, way to implement inheritance with local classes efficiently., advertisement, , 10. How many local classes can be defined inside a single function?, a) Only 1, b) Only 3, c) Only 5, d) As many as required, View Answer, Answer: d, Explanation: The local classes can be defined as required. There is no restriction on the, number of local classes that can be defined inside a function. But all those classes must, follow the rules and restrictions., 11. All the data members of local class must be ___________, a) Defined with declaration, b) Defined in constructor, c) Declared and defined in constructor, d) Declared using a member function, View Answer, Answer: b, Explanation: The data members follow the same rules as of simple classes. Hence the data, members must be declared first. Then their definition must be given using the constructors., 12. Can two different functions have local class with same name?, a) Yes, since local, b) No, names must be different, c) No, scope doesn’t work here
Page 103 :
d) No, ambiguity arises, View Answer, Answer: a, Explanation: The local classes can have same name if they belong to different functions. The, classes would be local to those specific functions and hence can have same name. This is, same as that of local variables concept., 13. What is the scope of local class?, a) Within the class only, b) Within the function, c) Within the program, d) One time creation and live till end of program, View Answer, Answer: b, Explanation: The scope of a local class is limited only within the function definition. The, function can use the class as usual as local variables. The class gets destroyed as soon as the, function is returned., advertisement, , 14. Can a function, other than the enclosing function of local class, access the class members?, a) Yes, using object, b) Yes, using direct call, c) Yes, using pointer, d) No, can’t access, View Answer, Answer: d, Explanation: The local classes are local to the specific enclosing function. Other functions, can’t access the class. Even if the pointers are used, the class must be alive when the, pointer is used. But this will not happen if the enclosing function is returned., 15. Which among the following is the main advantage of using local classes?, a) Make program more efficient, b) Makes program execution faster, c) Helps to add extra functionality to a function, d) Helps to add more members to a function, View Answer, Answer: c, Explanation: The closest answer is to add more functionalities to a function or to make some, specific functions to be generic. Adding more members to a function can be done directly but, to add some special functionality that are encapsulated, can be done using local classes., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers.
Page 104 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Member Functions, » Next - Object Oriented Programming Questions and Answers – Nested Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Member Functions, Object Oriented Programming Questions and Answers – Nested Class, advertisement, advertisement, , Recommended Posts:, 1. C++ Programming Examples on STL, 2. C Questions and Answers, 3. Java Programming Examples on Exception Handling, 4. C# Programming Examples on Inheritance, 5. C Tutorials, 6. Java Programming Examples on Collections, 7. Java Programming Examples on String Handling, 8. C# Programming Examples, 9. C Programming Examples on File Handling, 10. Java Programming Examples on File Handling, 11. Python Questions and Answers, 12. C# Basic Programming Examples, 13. Java Programming Examples on Multithreading, 14. Ruby Programming Questions and Answers, 15. Java Programming Examples on Java.Lang, 16. C# Programming Examples on Functions, 17. Java Programming Examples, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Nested Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Nested Class―., 1. Which among the following best describes a nested class?, a) Class inside a class
Page 105 :
b) Class inside a function, c) Class inside a package, d) Class inside a structure, View Answer, Answer: a, Explanation: If a class is defined inside another class, the inner class is termed as nested, class. The inner class is local to the enclosing class. Scope matters a lot here., advertisement, , 2. Which feature of OOP reduces the use of nested classes?, a) Encapsulation, b) Inheritance, c) Binding, d) Abstraction, View Answer, Answer: b, Explanation: Using inheritance we can have the security of the class being inherited. The, subclass can access the members of parent class. And have more feature than a nested class, being used., 3. How many categories are nested classes divided into?, a) 2, b) 3, c) 4, d) 5, View Answer, Answer: a, Explanation: The nested classes are divided into two main categories. Namely, Static and, non-static. The categories define how the classes can be used inside another class., 4. Non-static nested classes have access to _____________ from enclosing class., a) Private members, b) Protected members, c) Public members, d) All the members, View Answer, Answer: d, Explanation: The non-static nested class can access all the members of the enclosing class., All the data members and member functions can be accessed from the nested class. Even if, the members are private, they can be accessed., 5. Static nested classes doesn’t have access to _________________ from enclosing class., a) Private members, b) Protected members, c) Public members
Page 106 :
d) Any other members, View Answer, Answer: d, Explanation: The static nested class doesn’t have access to any other members of the, enclosing class. This is a rule that is made to ensure that only the data which can be common, to all the object is being accessed by the static nested class., advertisement, , 6. The nested class can be declared ___________________, a) Public, b) Private, c) Protected, d) Public, Protected, Private or Package private, View Answer, Answer: d, Explanation: The nested class can be declared with any specifier, unlike the outer classes, which can only be declared public or package private. This is flexibility given for the nested, class being a member of enclosing class., 7. Use of nested class ____________ encapsulation., a) Increases, b) Decreases, c) Doesn’t affect, d) Slightly decreases, View Answer, Answer: a, Explanation: The use of nested class increases encapsulation as the inner class is getting even, more grouped into the enclosing class. Firstly the class encapsulate the data, having nested, classes can increase the encapsulation even further., 8. Which among the following is the correct advantage/disadvantage of nested classes?, a) Makes the code more complex, b) Makes the code unreadable, c) Makes the code efficient and readable, d) Makes the code multithreaded, View Answer, Answer: c, Explanation: The use of nested classes makes the code more streamed towards a single, concept. This allows to group the most similar and related classes together and makes it even, more efficient and readable., 9. How to access static nested classes?, a) OuterClass.StaticNestedClass, b) OuterClass->StaticNestedClass, c) OuterClass(StaticNestedClass)
Page 107 :
d) OuterClass[StaticNestedClass], View Answer, Answer: a, Explanation: Like any other member of the class, the static nested class uses the dot operator, to be accessed. The reason behind is, the static classes can’t work with instances, hence, we use enclosing class name to access static nested class., 10. A nested class can have its own static members., a) True, b) False, View Answer, Answer: b, Explanation: The nested classes are associated with the object of the enclosing class. Hence, have direct access to the members of that object. Hence the inner class can’t have any, static members of its own. Otherwise the rule of static members would be violated using, enclosing class instance., advertisement, , 11. How to create object of the inner class?, a) OuterClass.InnerClass innerObject = outerObject.new InnerClass();, b) OuterClass.InnerClass innerObject = new InnerClass();, c) InnerClass innerObject = outerObject.new InnerClass();, d) OuterClass.InnerClass = outerObject.new InnerClass();, View Answer, Answer: a, Explanation: An instance of inner class can exist only within instance of outer class. To, instantiate the inner class, one must instantiate the outer class first. This can be done by the, correct syntax above., 12. What will be the output of the following code?, public class Test, {, public int a=0;, class innerClass, {, public int a=1;, void innermethod(int x), {, System.out.println(“value of x = ― + x);, System.out.println(“value of this.x = ― + this.x);, System.out.println(“value of Test.this.x = ― +, Test.T=this.x);, }, }, }, public static void main( String args[] ), {, Test t=new Test();, Test.innerClass im=t.new innerClass();, im.innermethod(55);
Page 108 :
}, , a), value of x = 55, value of this.x = 0, value of Test.this.x = 1, , b), value of x = 1, value of this.x = 0, value of Test.this.x = 55, advertisement, , c), value of x = 55, value of this.x = 1, value of Test.this.x = 0, , d), value of x = 0, value of this.x = 55, value of Test.this.x = 1, , View Answer, Answer: c, Explanation: The variable x denotes the parameter of the function. And this.x is the variable, of the inner class. Test.this.x is the variable of the outer class. Hence we get this output., , 13. Instance of inner class can exist only _______________ enclosing class., a) Within, b) Outside, c) Private to, d) Public to, View Answer, Answer: a, Explanation: The class defined inside another class is local to the enclosing class. This means, that the instance of inner class will not be valid outside the enclosing class. There is no, restriction for instance to be private or public always., 14. If a declaration of a member in inner class has the same name as that in the outer class,, then ________________ enclosing scope., a) Outer declaration shadows inner declaration in, b) Inner declaration shadows outer declaration in, c) Declaration gives compile time error, d) Declaration gives runtime error, View Answer
Page 109 :
Answer: b, Explanation: The inner class will have more preference for its local members than those of, the enclosing members. Hence it will shadow the enclosing class members. This process is, known as shadowing., 15. A static nested class is _____________ class in behavior that is nested in another, _________ class., a) Top level, top level, b) Top level, low level, c) Low level, top level, d) Low level, low level, View Answer, Answer: a, Explanation: Top level class encloses the other classes or have same preference as that of, other top level classes. Having a class inside the top level class is indirectly having a top level, class which higher degree of encapsulation., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Local Class, » Next - Object Oriented Programming Questions and Answers – Passing and Returning, Object with Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Local Class, Object Oriented Programming Questions and Answers – Passing and Returning Object, with Functions, advertisement, advertisement, , Recommended Posts:, 1., 2., 3., 4., 5., 6., 7., 8., 9., , C Programming Examples on Computational Geometry Problems & Algorithms, Java Programming Examples on Utility Classes, Python Programming Examples, C# Programming Examples on Exceptions, C# Programming Examples, Java Programming Examples on Computational Geometry Problems & Algorithms, C# Programming Examples on Functions, C# Programming Examples on Inheritance, Java Programming Examples on File Handling
Page 110 :
10. Java Programming Examples on String Handling, 11. Java Programming Examples on Networking, 12. Java Programming Examples on Multithreading, 13. Java Programming Examples on Exception Handling, 14. Java Programming Examples on Collections, 15. C# Basic Programming Examples, 16. Java Programming Examples on Java.Lang, 17. Java Programming Examples, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Passing and Returning, Object with Functions, « Prev, Next », , This set of Object Oriented Programming Interview Questions and Answers focuses on, “Passing and Returning Object with Functions―., 1. In how many ways can an object be passed to a function?, a) 1, b) 2, c) 3, d) 4, View Answer, Answer: c, Explanation: The objects can be passed in three ways. Pass by value, pass by reference and, pass by address. These are the general ways to pass the objects to a function., advertisement, , 2. If an object is passed by value _____________, a) A new copy of object is created implicitly, b) The object itself is used, c) Address of the object is passed, d) A new object is created with new random values, View Answer, Answer: a, Explanation: When an object is passed by value, a new object is created implicitly. This new, object uses the implicit values assignment, same as that of the object being passed.
Page 111 :
3. Pass by address passes the address of object _________ and pass by reference passes the, address of the object _________, a) Explicitly, explicitly, b) Implicitly, implicitly, c) Explicitly, Implicitly, d) Implicitly, explicitly, View Answer, Answer: c, Explanation: Pass by address uses the explicit address passing to the function whereas pass, by reference implicitly passes the address of the object., 4. If an object is passed by reference, the changes made in the function ___________, a) Are reflected to the main object of caller function too, b) Are reflected only in local scope of the called function, c) Are reflected to the copy of the object that is made during pass, d) Are reflected to caller function object and called function object also, View Answer, Answer: a, Explanation: When an object is passed by reference, its address is passed implicitly. This will, make changes to the main function whenever any modification is done., 5. Constructor function is not called when an object is passed to a function, will its destructor, be called when its copy is destroyed?, a) Yes, depending on code, b) Yes, must be called, c) No, since no constructor was called, d) No, since same object gets used, View Answer, Answer: b, Explanation: Even though the constructor is not called when the object is passed to a, function, the copy of the object is still created, where the values of the members are same., When the object have to be destroyed, the destructor is called to free the memory and, resources that the object might have reserved., advertisement, , 6. When an object is returned by a function, a _______________ is automatically created to, hold the return value., a) Temporary object, b) Virtual object, c) New object, d) Data member, View Answer, Answer: a, Explanation: The temporary object is created. It holds the return value. The values gets, assigned as required, and the temporary object gets destroyed.
Page 112 :
7. Is the destruction of temporary object safe (while returning object)?, a) Yes, the resources get free to use, b) Yes, other objects can use the memory space, c) No, unexpected side effects may occur, d) No, always gives rise to exceptions, View Answer, Answer: c, Explanation: The destruction of temporary variable may give rise to unexpected logical, errors. Consider the destructor which may free the dynamically allocated memory. But this, may abort the program if another is still trying to copy the values from that dynamic memory., 8. How to overcome the problem arising due to destruction of temporary object?, a) Overloading insertion operator, b) Overriding functions can be used, c) Overloading parenthesis or returning object, d) Overloading assignment operator and defining copy constructor, View Answer, Answer: d, Explanation: The problem can be solved by overloading the assignment operator to get the, values that might be getting returned while the destructor free the dynamic memory. Defining, copy constructor can help us to do this in even simpler way., 9. How many objects can be returned at once?, a) Only 1, b) Only 2, c) Only 16, d) As many as required, View Answer, Answer: a, Explanation: Like any other value, only one object can be returned at ones. The only possible, way to return more than one object is to return address of an object array. But that again, comes under returning object pointer., 10. What will be the output of the following code?, Class A, {, , advertisement, int i;, public : A(int n), {, i=n; cout<<―inside constructor ―;, }, ~A(), {, cout<<―destroying ―<<i;, }, void seti(int n), {, i=n;
Page 113 :
}, int geti(), {, return I;, }, };, void t(A ob), {, cout<<―something ―;, }, int main(), {, A a(1);, t(a);, cout<<―this is i in main ―;, cout<<a.geti();, }, , a) inside constructor something destroying 2this is i in main destroying 1, b) inside constructor something this is i in main destroying 1, c) inside constructor something destroying 2this is i in main, d) something destroying 2this is i in main destroying 1, View Answer, Answer: a, Explanation: Although the object constructor is called only ones, the destructor will be called, twice, because of destroying the copy of the object that is temporarily created. This is the, concept of how the object should be passed and manipulated., 11. It is necessary to return the object if it was passed by reference to a function., a) Yes, since the object must be same in caller function, b) Yes, since the caller function needs to reflect the changes, c) No, the changes are made automatically, d) No, the changes are made explicitly, View Answer, Answer: c, Explanation: Having the address being passed to the function, the changes are automatically, made to the main function. In all the cases if the address is being used, the same memory, location will be updated with new values., 12. How many objects can be passed to a function simultaneously?, a) Only 1, b) Only an array, c) Only 1 or an array, d) As many as required, View Answer, Answer: d, Explanation: There is no limit to how many objects can be passed. This works in same way as, that any other variable gets passed. Array and object can be passed at same time also.
Page 114 :
13. If an object is passed by address, will be constructor be called?, a) Yes, to allocate the memory, b) Yes, to initialize the members, c) No, values are copied, d) No, temporary object is created, View Answer, Answer: c, Explanation: A copy of all the values is created. If the constructor is called, there will be a, compile time error or memory shortage. This happens because each time a constructor is, called, it try to call itself again and that goes infinite times., advertisement, , 14. Is it possible that an object of is passed to a function, and the function also have an object, of same name?, a) No, Duplicate declaration is not allowed, b) No, 2 objects will be created, c) Yes, Scopes are different, d) Yes, life span is different, View Answer, Answer: a, Explanation: There can’t be more than one variable or object with the same name in same, scope. The scope is same, since the object is passed, it becomes local to function and hence, function can’t have one more object of same name., 15. Passing an object using copy constructor and pass by value are same., a) True, b) False, View Answer, Answer: b, Explanation: The copy constructor is used to copy the values from one object to other. Pass, by values is not same as copy constructor method. Actually the pass by value method uses a, copy constructor to copy the values in a local object., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Interviews, here is complete set of, 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Nested Class, » Next - Object Oriented Programming Questions and Answers – Object Reference, Categories Object Oriented Programming MCQs Post navigation
Page 115 :
Object Oriented Programming Questions and Answers – Nested Class, Object Oriented Programming Questions and Answers – Object Reference, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Files, 2. C# Programming Examples on Networking, 3. Simple C Programs, 4. C Programming Examples on Linked List, 5. Java Programming Examples, 6. C Programming Examples on Strings, 7. C# Programming Examples on Mathematics, 8. Java Programming Examples on Collections, 9. Java Programming Examples on String Handling, 10. Java Programming Examples on Networking, 11. Java Programming Examples on Inheritance, 12. Java Programming Examples on Utility Classes, 13. C# Programming Examples on Arrays, 14. Java Programming Examples on File Handling, 15. Java Programming Examples on Mathematical Functions, 16. Java Programming Examples on Java.Lang, 17. C Programming Examples on Mathematical Functions, 18. Java Programming Examples on Classes, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Object Reference, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Object Reference―., 1. What is reference to an object?, a) It is address of an object, b) It is address of where the variables and methods of object are stored, c) It is pointer having address of an object, d) It is address of only variables and not the methods of an object, View Answer, Answer: b, Explanation: Reference indicates the address where the object’s variables and methods
Page 116 :
are stored. It is not actual address of the object. This is done to directly use the variables and, methods whenever required., advertisement, , 2. Whenever an object is assigned to a variable or passed to a method ________________, a) Actually the objects aren’t used, b) Actually only the objects are used, c) Actually a pointer to an object is used, d) Actually copy of object is used, View Answer, Answer: a, Explanation: Whenever an object is assigned to a variable or passed to a method, we, aren’t actually using objects there. Actually the reference to the objects is used. The, reference makes a lot of difference as the main object may or may not get affected depending, on the code., 3. Does use of object reference in assignment or passing means copy of the object is being, used?, a) No, because the copy would create a new temporary variable, b) No, because the copy would not help to make changes to main object, c) Yes, because the reference directly means using address, d) Yes, because the reference directly means the constructors are involved, View Answer, Answer: c, Explanation: We can’t say that the reference involves constructors in passing the objects, to some method. The reference is used to denote the addresses and hence to point to the main, object itself. There is no copy involved., 4. What will be the output of the following code?, import java.awt.Point;, class Testing, {, public static void main(String[] args), {, Point p1,p2;, p1=new Point(100,100);, p2=p1;, p1.x=200;, p1.y=200;, System.out.println(“Point 1: ― + p1.x + ―, “ +, p1.y);, System.out.println(“Point 2: ― + p2.x + ―, “ +, p2.y);, }, }, , a), Point 1: 100, 100, Point 2: 200, 200, advertisement
Page 117 :
b), Point 1: 200, 200, Point 2: 100, 100, , c), Point 1: 100, 100, Point 2: 100, 100, , d), Point 1: 200, 200, Point 2: 200, 200, , View Answer, Answer: d, Explanation: The expected output would be like p2 with values 100, 100. But this is not the, case. The tricky part is assignment used (p2=p1;). Here a reference is created from object p1, to p2, and not any new object that would copy p1’s values. Hence when we change the, values of p1 object members. There changes are reflected to the object p2 also., , 5. Is there any explicit use of pointers in java that would be applicable to objects?, a) Yes, we use reference for this purpose, b) Yes, we use java arrays for this purpose, c) No, implicit pointing is possible, d) No, direct class names should be used, View Answer, Answer: c, Explanation: The question clearly asks if there is any explicit use of pointers related to, objects. Pointers are not applicable in java first of all. Secondly, the pointing in java is, achieved implicitly using the references and object arrays., advertisement, , 6. Can a super class object give reference to a subclass method?, a) No, it is not possible, b) Maybe, it is possible, c) No, it’s not possible, d) No, It’s not possible in few cases only, View Answer, Answer: c, Explanation: The object of a super class can never refer to methods of a subclass. Whereas, vice versa is possible. If there is an overridden function in subclass, then the object of super, class will execute the method of itself and not from the subclass., 7. What will be the output of the following code?, import java.awt.Point;, class Testing
Page 118 :
{, public static void main(String[] args), {, Point t1,t2,t3;, t1=new Point(100,100);, t2=t1;, t3=t1;, t1.x=200;, t1.y=200;, t2.x=300;, t3.y=500;, System.out.println(“Point 1: ― + p1.x + ―, “ +, p1.y);, }, }, , a) Point 1: 200, 200, b) Point 1: 100,100, c) Point 1: 300, 300, d) Point 1: 300, 500, View Answer, Answer: d, Explanation: When references are used, all the variables point to the same object. Whenever, any of the variable changes any values, it will be reflected to all the variables pointing to the, same object., 8. If a reference variable is declared final then _________________, a) It can never be reassigned to refer to a different object, b) It can be assigned to refer to any object anytime, c) It can never be assigned with any object, d) It can be assigned with 2 or more objects simultaneously, View Answer, Answer: a, Explanation: Since the variable is declared final. It will have a constant value throughout the, program. It can refer to only one object at a time. And if it was made to refer to none of the, object, it would have got no use., advertisement, , 9. Which of the members are referred by this pointer usually (Java)?, a) Members of class where this is used, b) Member of the parent class where this is used, c) Members that are passed as argument to the object, d) Pointers are not applicable in java, View Answer, Answer: a, Explanation: We use this pointer to differentiate the members of the class where this is used, to the other inherited or passed variables. The local variables are denoted with this. Or, specifically the members of class only.
Page 119 :
10. How to refer to method of nested class?, a) enclosingClassObject.innerClassObject.method();, b) innerClassObject.method();, c) method();, d) depends on where the method is being called, View Answer, Answer: d, Explanation: This depends on where the method is being called. If the method is called inside, the enclosing class itself. Then we can’t use object of enclosing class. If the method is, being called within the inner class itself, then its object will also be of no use., 11. How many objects can be referenced from the same variables?, a) One at a time, b) Many at a time, c) Many using array name, d) 7 at max at same time, View Answer, Answer: a, Explanation: There should not be any confusion in how many references can be made from a, single variable. A single variable can only point to one object at a time. Even if it’s an, array, the name of the array is used and is considered one object name only (representing first, array element)., 12. Java handles memory dynamically and references are deleted as soon as they are out of, scope., a) True, b) False, View Answer, Answer: a, Explanation: In Java, it is inbuilt feature that handles all the memory dynamically. It is not, necessary to free or destroy all the references made from a function which is going out of, scope. You can call destroy or free methods explicitly but there is no mandatory rule., 13. Which among the following is true?, a) Object referencing refers to methods address, b) Object referencing refers to variable of object, c) Object referencing points to same address, if assigned by variables, d) Object referencing is used to point methods, View Answer, Answer: c, Explanation: The object referencing will point to the same address if variables are assigned., All the variables might have a different name but they will point to the same memory, location. This is most basic concept of references., 14. Invoking a method on a particular object is ____________ sending a message to that, object.
Page 120 :
a) Different from, b) Same as, c) Somewhat similar, d) Part of, View Answer, Answer: b, Explanation: The methods invoked on a particular object is same as sending a message with, same values to that object. Message would contain values in a particular format that can be, used by the object. And calling a method would be just another way to do the same task., 15. Can reference to an object be returned from a method?, a) Yes, always possible, b) Yes, but not always, c) No, never possible, d) No, Not possible because referred element would be destroyed, View Answer, Answer: b, Explanation: This is possible but not always, since the reference being returned may get, destroyed with the return of method. This is an undesirable condition, hence it is not always, possible to return references. But it is always possible if the referred element is not local to, the method., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Passing and Returning, Object with Functions, » Next - Object Oriented Programming Questions and Answers – Memory Allocation of, Object, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Passing and Returning Object, with Functions, Object Oriented Programming Questions and Answers – Memory Allocation of Object, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Mathematical Functions, 2. Java Programming Examples on Computational Geometry Problems & Algorithms
Page 121 :
3. Simple Java Programs, 4. Java Programming Examples on Event Handling, 5. Java Programming Examples on Data-Structures, 6. C# Programming Examples on Delegates, 7. Java Programming Examples on Collection API, 8. Java Programming Examples on Exception Handling, 9. Java Programming Examples on File Handling, 10. Ruby Programming Questions and Answers, 11. Java Programming Examples on Networking, 12. Java Programming Examples on Collections, 13. Java Programming Examples, 14. Java Programming Examples on String Handling, 15. Java Programming Examples on Utility Classes, 16. Java Programming Examples on Multithreading, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Memory Allocation of, Object, « Prev, Next », , This set of Object Oriented Programming test focuses on “Memory Allocation of, Object―., 1. What does memory allocation for objects mean?, a) Actual creation and memory allocation for object members, b) Creation of member functions, c) Creation of data members for a class, d) Actual creation and data declaration for object members, View Answer, Answer: a, Explanation: The memory allocated for the object members indicates actual creation of the, object members. This is known as memory allocation for object., advertisement, , 2. Where is the memory allocated for the objects?, a) HDD, b) Cache, c) RAM
Page 122 :
d) ROM, View Answer, Answer: c, Explanation: The memory for the objects or any other data is allocated in RAM initially. This, is while we run a program all the memory allocation takes place in some RAM segments., Arrays in heap and local members in stack etc., 3. When is the memory allocated for an object?, a) At declaration of object, b) At compile time, c) When object constructor is called, d) When object is initialized to another object, View Answer, Answer: c, Explanation: The object memory allocation takes place when the object constructor is called., Declaration of an object doesn’t mean that memory is allocated for its members. If object, is initialized with another object, it may just get a reference to the previously created object., 4. Using new is type safe as _______________________, a) It require to be specified with type of data, b) It doesn’t require to be specified with type of data, c) It requires the name of data, d) It allocated memory for the data, View Answer, Answer: b, Explanation: The new is type safe because we don’t have to specify the type of data that, have to be allocated with memory. We can directly use it with data name. Name of the data, doesn’t matter though for type of memory allocation though., 5. Which of the following function can be used for dynamic memory allocation of objects?, a) malloc(), b) calloc(), c) create(), d) malloc() and calloc(), View Answer, Answer: d, Explanation: The malloc() function can be used to allocate dynamic memory for objects., Function calloc() can also be use. These functions differ in the way they allocate memory for, objects., advertisement, , 6. How much memory will be allocated for an object of class given below?, class Test, {, int mark1;, int mark2;
Page 123 :
float avg;, char name[10];, };, , a) 22 Bytes, b) 24 Bytes, c) 20 Bytes, d) 18 Bytes, View Answer, Answer: a, Explanation: The size of an object of the class given in question will be of size 22 bytes. This, is because the size of an object is always equal to the sum of sizes of the data members of the, class, except static members., 7. Which keyword among the following can be used to declare an array of objects in java?, a) new, b) create, c) allocate, d) arr, View Answer, Answer: a, Explanation: The keyword new can be used to declare an array of objects in java. The syntax, must be specified with an object pointer which is assigned with a memory space containing, the required number of object space. Even initialization can be done directly., 8. When is the memory allocated for an object gets free?, a) At termination of program, b) When object goes out of scope, c) When main function ends, d) When system restarts, View Answer, Answer: b, Explanation: Whenever an object goes out of scope, the deletion of allocation memory takes, place. Actually the data is not deleted, instead the memory space is flagged to be free for, further use. Hence whenever an object goes out of scope the object members become useless, and hence memory is set free., advertisement, , 9. Which among the following keyword can be used to free the allocated memory for an, object?, a) delete, b) free, c) either delete or free, d) only delete, View Answer, Answer: c, Explanation: The memory allocated for an object is usually automatically made free. But if
Page 124 :
explicitly memory has to be made free then we can use either free or delete keywords, depending on programming languages., 10. Which function is called whenever an object goes out of scope?, a) Destructor function, b) Constructor function, c) Delete function, d) Free function, View Answer, Answer: a, Explanation: The destructor function of the class is called whenever an object goes out of, scope. This is because the destructor set all the resources, acquired by the object, free. This is, an implicit work of compiler., 11. Which operator can be used to check the size of an object?, a) sizeof(objectName), b) size(objectName), c) sizeofobject(objectName), d) sizedobject(objectName), View Answer, Answer: a, Explanation: The sizeof operator is used to get the size of an already created object. This, operator must constail keyword sizeof(objectName). The output will give the number of, bytes acquired by a single object of some class., 12. The memory allocated for an object ____________________, a) Can be only dynamic, b) Can be only static, c) Can be static or dynamic, d) Can’t be done using dynamic functions, View Answer, Answer: c, Explanation: The memory allocation for an object can be static or dynamic. The static, memory allocation is when an object is declared directly without using any function usually., And dynamic allocation is when we use some dynamic allocation function to allocate, memory for data member of an object., 13. If an object is declared in a user defined function __________________, a) Its memory is allocated in stack, b) Its memory is allocated in heap, c) Its memory is allocated in HDD, d) Its memory is allocated in cache, View Answer, Answer: a, Explanation: The memory for any data or object that are used in a user defined function are, always allocated in the stack. This is to ensure that the object is destroyed as soon as the
Page 125 :
function is returned. Also this ensures that the correct memory allocation and destruction is, performed., advertisement, , 14. In java, ____________________ takes care of managing memory for objects, dynamically., a) Free collector, b) Dust collector, c) Memory manager, d) Garbage collector, View Answer, Answer: d, Explanation: The garbage collector in java takes care of the memory allocations and their, deletions dynamically. When an object is no more required then the garbage collector deletes, the object and free up all the resources that were held by that object., 15. Which operator can be used to free the memory allocated for an object in C++?, a) Free(), b) delete, c) Unallocate, d) Collect, View Answer, Answer: b, Explanation: The delete operator in C++ can be used to free the memory and resources held, by an object. The function can be called explicitly whenever required. In C++ memory, management must be done by the programmer. There is no automatic memory management, in C++., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for tests, here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Object Reference, » Next - Object Oriented Programming Questions and Answers – Object Array, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Object Reference, Object Oriented Programming Questions and Answers – Object Array, advertisement, advertisement, , Recommended Posts:
Page 126 :
1. C Programming Examples on Numerical Problems & Algorithms, 2. Java Programming Examples on Utility Classes, 3. C Tutorials, 4. C++ Programming Examples on Computational Geometry Problems & Algorithms, 5. C Programming Examples on Computational Geometry Problems & Algorithms, 6. Python Programming Examples on Stacks & Queues, 7. Java Programming Examples on String Handling, 8. C# Programming Examples on Files, 9. C# Programming Examples on Functions, 10. Java Programming Examples on Data-Structures, 11. Java Programming Examples, 12. Java Programming Examples on Inheritance, 13. Java Programming Examples on Collections, 14. Ruby Programming Questions and Answers, 15. C Programming Examples on Linked List, 16. Java Programming Examples on Classes, 17. Java Programming Examples on File Handling, 18. Java Programming Examples on Java.Lang, 19. C Programming Examples on Stacks & Queues, 20. Object Oriented Programming Questions and Answers – Assigning Objects, advertisement, , Object Oriented Programming Questions, and Answers – Object Array, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Object Array―., 1. What is an array of objects?, a) An array of instances of class represented by single name, b) An array of instances of class represented by more than one name, c) An array of instances which have more than 2 instances, d) An array of instances which have different types, View Answer, Answer: a, Explanation: The array of objects an array of instances of a class. The array is represented by, a single name. The array name is itself a pointer. Array name represents the first object., advertisement, , 2. Which among the following is a mandatory condition for array of objects?, a) All the objects should be of different class, b) All the objects should be of same program classes, c) All the objects should be of same class
Page 127 :
d) All the objects should have different data, View Answer, Answer: c, Explanation: The objects of an array must be of same class. This is mandatory because array, is set of same type of elements. The objects of same class are considered to be of same type., 3. What is the type of elements of array of objects?, a) Class, b) Void, c) String, d) Null, View Answer, Answer: a, Explanation: The class itself is the type of elements of array of objects. All the objects, possess the same properties. Like any other primitive data type, the objects are of their, respective class type., 4. If array of objects is declared as given below, which is the limitation on objects?, Class_name arrayName[size];, , a) The objects will have same values, b) The objects will not be initialized individually, c) The objects can never be initialized, d) The objects will have same data, View Answer, Answer: b, Explanation: If the syntax given, is used to declare the array of objects, then the objects, can’t be initialized individually. All the objects will have to be initialized after this, declaration., advertisement, , 5. Which is the condition that must be followed if the array of objects is declared without, initialization, only with size of array?, a) The class should have separate constructor for each object, b) The class must have no constructors, c) The class should not have any member function, d) The class must have a default or zero argument constructor, View Answer, Answer: d, Explanation: The class must have a default/zero argument constructor. Since the declaration, is done by only specifying the size of array, the class must have default a construct to be, called by default to reserve memory for each object. Also, we can’t specify the arguments, in this type of declaration hence the class should provide a default initialization.
Page 128 :
6. When are the array of objects without any initialization useful?, a) When object data is not required just after the declaration, b) When initialization of object data is to be made by the compiler, c) When object data doesn’t matter in the program, d) When the object should contain garbage data, View Answer, Answer: a, Explanation: Sometimes the object data is not mandatory to be used just after the declaration, or may be the program requires the data to be updated according to what user inputs. Hence, only declaration us also useful., 7. If constructor arguments are passed to objects of array then ____________ if the, constructors are overloaded., a) It is mandatory to pass same number of arguments to all the objects, b) It is mandatory to pass same type of arguments to all the objects, c) It is not mandatory to call same constructor for all the objects, d) It is mandatory to call same constructor for all the constructors, View Answer, Answer: c, Explanation: It is not mandatory to call the same constructor for all the objects in an array if, initialized with the declaration. The objects can be passed with different set of arguments in, the same syntax, separated by commas., 8. How the objects of array can be denoted?, a) Indices, b) Name, c) Random numbers, d) Alphabets, View Answer, Answer: a, Explanation: Different objects in an array can be denoted with the indices of array. The first, object is denoted by 0. And the further indices denote the next objects in sequence of array., 9. The objects in an object array _______________________, a) Can be created without use of constructor, b) Can be created without calling default constructor, c) Can’t be created with use of constructor, d) Can’t be created without calling default constructor, View Answer, Answer: b, Explanation: The objects need some constructor to get the memory spaced reserved for those., If the default constructor is not used then we can use some arguments constructor which will, reserve the memory for the objects. The objects can be passed with constructor arguments, during declaration., advertisement
Page 129 :
10. The Object array is created in _____________________, a) Heap memory, b) Stack memory, c) HDD, d) ROM, View Answer, Answer: a, Explanation: If the object arrays are declared dynamically, then the memory will be reserved, on heap. The memory for objects will be on stack only if some constructor or some call and, return tasks are happening. The program doesn’t run on HDD and ROM is not used for, the execution of programs., 11. If an array of objects is of size 10 and a data value have to be retrieved from 5th object, then ________________ syntax should be used., a) Array_Name[4].data_variable_name;, b) Data_Type Array_Name[4].data_variable_name;, c) Array_Name[4].data_variable_name.value;, d) Array_Name[4].data_variable_name(value);, View Answer, Answer: a, Explanation: The array name with the index of fifth element is called, i.e. index 4. Then the, dot operator is used to access the data member of that object. This Allows us to access the, data members of all the objects in an object array., 12. Can we have two dimensional object array?, a) Yes, always, b) Yes, only if primitive type array, c) No, since two indices are impossible, d) No, never, View Answer, Answer: a, Explanation: A two dimensional array can always be created. There is no rule that only, primitive type objects can have more than one dimension. The object array can also be made, 2 dimensional., 13. From which index does the array of objects start?, a) 0, b) 1, c) 2, d) 3, View Answer, Answer: a, Explanation: The index must start from 0. The index ends at size – 1 index. This is because, the index is always till n-1 where n is the total number of beads.
Page 130 :
14. Two dimensional array can’t be initialized with the declaration., a) True, b) False, View Answer, Answer: b, Explanation: The two dimensional arrays can also be initialized using curly brackets. For, each set, values in curly bracket. And then another bracket is added at first and end. This, ensures that all the code belongs to the user., advertisement, , 15. Is an array of characters always a string?, a) Yes, always, b) Yes, if each character is terminated by null, c) No, since each character is terminated by null, d) No, never, View Answer, Answer: d, Explanation: The character arrays are not the same as string. The string once created then, remains the same. The character array values may change., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Memory Allocation of, Object, » Next - Object Oriented Programming Questions and Answers – Object Use, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Memory Allocation of Object, Object Oriented Programming Questions and Answers – Object Use, advertisement, advertisement, , Recommended Posts:, 1., 2., 3., 4., 5., 6., , C# Programming Examples on Files, Java Programming Examples on Arrays, C# Programming Examples on Exceptions, Java Programming Examples on Exception Handling, Ruby Programming Questions and Answers, Java Programming Examples on Multithreading
Page 131 :
7. C# Programming Examples on LINQ, 8. C Programming Examples on Arrays, 9. C Programming Examples on Stacks & Queues, 10. Java Programming Examples on Data-Structures, 11. Java Programming Examples on String Handling, 12. Java Programming Examples on File Handling, 13. C# Programming Examples on Arrays, 14. Java Programming Examples on Utility Classes, 15. Java Programming Examples on Inheritance, 16. Java Programming Examples, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Collections, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Object Use, « Prev, Next », , This set of Object Oriented Programming MCQs focuses on “Object Use―., 1. Which among the following is the main use of object?, a) To create instance of a function, b) To create instance of a program, c) To create instance of class, d) To create instance of structures, View Answer, Answer: c, Explanation: The objects are used to create an instance of a class. Objects can represent a, class in an independent form. The basic blueprint, that contains the information of the type of, data that can be stored in an object, is given by the class., advertisement, , 2. Which among the following is not a property of an object?, a) Identity, b) Properties, c) Attributes, d) Names, View Answer, Answer: d, Explanation: The names are not property of an object. The identity can be in any form like, address or name of object but name can’t be termed as only identity of an object. The, objects contain attributes that define what type of data an object can store.
Page 132 :
3. What is function object?, a) An object with a single function, b) An object with only functions, c) An object with more than one function, d) An object with no functions, View Answer, Answer: a, Explanation: A function object is an object with single function. In C++ a function object can, be like operator() function. This acts more like a function rather than an object., 4. Immutable object are used ______________________, a) To set up as a fixed state, b) To set up variable object, c) To set up an object of abstract class, d) To set up an object of derived class, View Answer, Answer: a, Explanation: An immutable object can be created for an object which has to be fixed with, values. The object data will not be changed throughout the program. This can be useful to, eliminate the unintentional changes in the data of object., 5. Which object can be used to contain other objects?, a) First class object, b) Derived class object, c) Container object, d) Enclosure object, View Answer, Answer: c, Explanation: A container object can be used to contain other objects. Container object is an, ADT. Its object are collection of other objects. Some specific rules apply to these types of, objects., advertisement, , 6. A factory object is used ______________________, a) To create new classes, b) To create new function, c) To create new data members, d) To create new objects, View Answer, Answer:d, Explanation: The factory object is an object that can be used to create other objects. If it is, seen formally, it behaves like a method that will return object on its use. The object returned, is assumed to be a new object., 7. What are singleton objects?, a) The only two objects of a class throughout the program
Page 133 :
b) The only object of a class throughout the program, c) The objects that are alive throughout the program, d) The objects that are created and then deleted without use, View Answer, Answer: b, Explanation: If a class has only one object created and that is the only object of the class., Then the object is known as the singleton object. But only if that object is the only object of, the class and no other object is created for that class., 8. Object cout and cin _________________, a) Can be used directly with << and >> symbols respectively, b) Can be used directly with >> and << symbols respectively, c) Must be used as a function which accepts 2 arguments, d) Must be used as a function which accepts 3 arguments, View Answer, Answer: a, Explanation: The cin and cout objects can be used directly with the >> and << operators, respectively. The objects are of iostream class. Class iostream is an inbuilt class., 9. Objects type ____________________, a) Can be changed in runtime, b) Can’t be changed in runtime, c) Can be changed in compile time, d) May or may not get changed, View Answer, Answer: b, Explanation: The object types are always fixed. Once the object is created of a specific type, then it can’t be changed. Neither at runtime nor at compile time., advertisement, , 10. An object can be used to represent _________________, a) A real world entity, b) A real function, c) Some real data only, d) Some function only, View Answer, Answer: a, Explanation: The objects are actually meant to represent an entity. The classes are real world, object’s blueprint. The classes then are used to create an entity representation., 11. Objects can be used _____________________, a) To access any member of a class, b) To access only public members of a class, c) To access only protected members of a class, d) To access only private members of a class, View Answer
Page 134 :
Answer: b, Explanation: The objects are created for a specific class. Then the objects can be used to, access the public members of a class. The members can be the data members or the member, functions of the class., 12. Which among the following is not a use of object?, a) Defining a member function, b) Accessing data members, c) Creating instance of a class, d) Using class members, View Answer, Answer: a, Explanation: The objects can’t be used to define any member function. Member functions, must be defined by the class only. Objects can only access the members and use them., 13. Which object can be used to access the standard input?, a) System.inner, b) cin, c) System.stdin, d) console.input, View Answer, Answer: b, Explanation: Object cin can be used to take input from the standard input. It is used in C++., In java we can use System.in for the standard input stream. The syntax changes from, language to language., advertisement, , 14. A single object can be used __________________, a) As only two class types at a time, b) As only three class types at a time, c) As only one class type at a time, d) As of as many class types as required, View Answer, Answer: c, Explanation: The object can be of only one type. The type of an object can’t be changed., Object type is mandatory to be of one class type to ensure the type and number of data, members it have., 15. If same object name is given to different objects of different class then _____________, a) Its compile time error, b) Its runtime error, c) It’s not an error, d) Program suns smooth, View Answer, Answer: a, Explanation: It is a compile time error as the compiler doesn’t allow the same name
Page 135 :
objects to be declared more than once. Compiler produces multiple declaration errors. Every, object must have a different name., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice MCQs on all areas of Object Oriented Programming, here is complete set of, 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Object Array, » Next - Object Oriented Programming Questions and Answers – Abstract Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Object Array, Object Oriented Programming Questions and Answers – Abstract Class, advertisement, advertisement, , Recommended Posts:, 1. R Programming Questions and Answers, 2. C# Programming Examples on Arrays, 3. C# Programming Examples on Interfaces, 4. Java Programming Examples on Networking, 5. C# Programming Examples on Delegates, 6. Java Programming Examples, 7. Java Programming Examples on Utility Classes, 8. C# Programming Examples on Events, 9. C# Basic Programming Examples, 10. C# Programming Examples on Files, 11. Java Programming Examples on Multithreading, 12. Java Programming Examples on Exception Handling, 13. C# Programming Examples on Functions, 14. C# Programming Examples on Data Structures, 15. Java Programming Examples on Java.Lang, 16. Java Programming Examples on File Handling, 17. Java Programming Examples on Collections, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement
Page 136 :
Object Oriented Programming Questions, and Answers – Abstract Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Abstract Class―., 1. Which among the following best describes abstract classes?, a) If a class has more than one virtual function, it’s abstract class, b) If a class have only one pure virtual function, it’s abstract class, c) If a class has at least one pure virtual function, it’s abstract class, d) If a class has all the pure virtual functions only, then it’s abstract class, View Answer, Answer: c, Explanation: The condition for a class to be called abstract class is that it must have at least, one pure virtual function. The keyword abstract must be used while defining abstract class in, java., advertisement, , 2. Can abstract class have main() function defined inside it?, a) Yes, depending on return type of main(), b) Yes, always, c) No, main must not be defined inside abstract class, d) No, because main() is not abstract function, View Answer, Answer: b, Explanation: This is a property of abstract class. It can define main() function inside it. There, is no restriction on its definition and implementation., 3. If there is an abstract method in a class then, ________________, a) Class must be abstract class, b) Class may or may not be abstract class, c) Class is generic, d) Class must be public, View Answer, Answer: a, Explanation: It is a rule that if a class have even one abstract method, it must be an abstract, class. If this rule was not made, the abstract methods would have got skipped to get defined, in some places which are undesirable with the idea of abstract class., 4. If a class is extending/inheriting another abstract class having abstract method, then, _______________________, a) Either implementation of method or making class abstract is mandatory
Page 137 :
b) Implementation of the method in derived class is mandatory, c) Making the derived class also abstract is mandatory, d) It’s not mandatory to implement the abstract method of parent class, View Answer, Answer: a, Explanation: Either of the two things must be done, either implementation or declaration of, class as abstract. This is done to ensure that the method intended to be defined by other, classes gets defined at every possible class., 5. Abstract class A has 4 virtual functions. Abstract class B defines only 2 of those member, functions as it extends class A. Class C extends class B and implements the other two, member functions of class A. Choose the correct option below., a) Program won’t run as all the methods are not defined by B, b) Program won’t run as C is not inheriting A directly, c) Program won’t run as multiple inheritance is used, d) Program runs correctly, View Answer, Answer: d, Explanation: The program runs correctly. This is because even class B is abstract so it’s, not mandatory to define all the virtual functions. Class C is not abstract but all the virtual, functions have been implemented will that class., advertisement, , 6. Abstract classes can ____________________ instances., a) Never have, b) Always have, c) Have array of, d) Have pointer of, View Answer, Answer: a, Explanation: When an abstract class is defined, it won’t be having the implementation of, at least one function. This will restrict the class to have any constructor. When the class, doesn’t have constructor, there won’t be any instance of that class., 7. We ___________________ to an abstract class., a) Can create pointers, b) Can create references, c) Can create pointers or references, d) Can’t create any reference, pointer or instance, View Answer, Answer: c, Explanation: Even though there can’t be any instance of abstract class. We can always, create pointer or reference to abstract class. The member functions which have some, implementation inside abstract itself can be used with these references.
Page 138 :
8. Which among the following is an important use of abstract classes?, a) Header files, b) Class Libraries, c) Class definitions, d) Class inheritance, View Answer, Answer: b, Explanation: The abstract classes can be used to create a generic, extensible class library that, can be used by other programmers. This helps us to get some already implemented codes and, functions that might have not been provided by the programming language itself., 9. Use of pointers or reference to an abstract class gives rise to which among the following, feature?, a) Static Polymorphism, b) Runtime polymorphism, c) Compile time Polymorphism, d) Polymorphism within methods, View Answer, Answer: b, Explanation: The runtime polymorphism is supported by reference and pointer to an abstract, class. This relies upon base class pointer and reference to select the proper virtual function., advertisement, , 10. The abstract classes in java can _________________, a) Implement constructors, b) Can’t implement constructor, c) Can implement only unimplemented methods, d) Can’t implement any type of constructor, View Answer, Answer: a, Explanation: The abstract classes in java can define a constructor. Even though instance, can’t be created. But in this way, only during constructor chaining, constructor can be, called. When instance of concrete implementation class is created, it’s known as, constructor chaining., 11. Abstract class can’t be final in java., a) True, b) False, View Answer, Answer: a, Explanation: If an abstract class is made final in java, it will stop the abstract class from being, extended. And if the class is not getting extended, there won’t be another class to, implement the virtual functions. Due to this contradicting fact, it can’t be final in java., 12. Can abstract classes have static methods (Java)?, a) Yes, always
Page 139 :
b) Yes, but depends on code, c) No, never, d) No, static members can’t have different values, View Answer, Answer: a, Explanation: There is no restriction on declaring static methods. The only condition is that, the virtual functions must have some definition in the program., 13. It is _________________________ to have an abstract method., a) Not mandatory for an static class, b) Not mandatory for a derived class, c) Not mandatory for an abstract class, d) Not mandatory for parent class, View Answer, Answer: c, Explanation: Derived, parent and static classes can’t have abstract method (We can’t, say what type of these classes is). And for abstract class it’s not mandatory to have, abstract method. But if any abstract method is there inside a class, then class must be abstract, type., advertisement, , 14. How many abstract classes can a single program contain?, a) At most 1, b) At least 1, c) At most 127, d) As many as required, View Answer, Answer: d, Explanation: There is no restriction on the number of abstract classes that can be defined, inside a single program. The programs can use as many abstract classes as required. But the, functions with no body must be implemented., 15. Is it necessary that all the abstract methods must be defined from an abstract class?, a) Yes, depending on code, b) Yes, always, c) No, never, d) No, if function is not used, no definition is required, View Answer, Answer: b, Explanation: That is the rule of programming language that each function declared, must, have some definition. There can’t be some abstract method that remains undefined. Even, if it’s there, it would result in compile time error., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs).
Page 140 :
To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Object Use, » Next - Object Oriented Programming Questions and Answers – Template Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Object Use, Object Oriented Programming Questions and Answers – Template Class, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples on Stacks & Queues, 2. C# Programming Examples on Delegates, 3. C++ Programming Examples on STL, 4. Java Programming Examples on Event Handling, 5. Java Programming Examples on Numerical Problems & Algorithms, 6. Java Programming Examples on Data-Structures, 7. C# Programming Examples, 8. Java Programming Examples on Mathematical Functions, 9. Java Programming Examples on Multithreading, 10. Java Programming Examples on Utility Classes, 11. Java Programming Examples on Collection API, 12. Java Programming Examples on Networking, 13. Java Programming Examples on Java.Lang, 14. C# Programming Examples on Inheritance, 15. Java Programming Examples on Exception Handling, 16. Java Programming Examples, 17. C# Programming Examples on Functions, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Template Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Template Class―.
Page 141 :
1. A template class can have _____________, a) More than one generic data type, b) Only one generic data type, c) At most two data types, d) Only generic type of integers and not characters, View Answer, Answer: a, Explanation: The template class can support more than one data type. The only thing is to add, all the data types required in a list separated by comma within template specification., advertisement, , 2. Which among the following is the proper syntax for the template class?, a) template <typename T1, typename T2>;, b) Template <typename T1, typename T2>;, c) template <typename T> T named(T x, T y){ }, d) Template <typename T1, typename T2> T1 named(T1 x, T2 y){ }, View Answer, Answer: c, Explanation: The syntax must start with keyword template, case sensitive. Then it should, include the typename and a variable to denote it. Then whenever that variable is used, it, replaces it with the data type needed., 3. Can default arguments be used with the template class?, a) Yes, in some special cases, b) Yes, always, c) No, it must satisfy some specific conditions first, d) No, it can’t be done, View Answer, Answer: b, Explanation: The template class can use default arguments. This is used to specify the data, type to be considered if it is not specified while passing to the generic class. The default type, will be used., 4. What is the syntax to use explicit class specialization?, a) template <int> class myClass<>{ }, b) template <int> class myClass<int>{ }, c) template <> class myClass<>{ }, d) template <> class myClass<int>{ }, View Answer, Answer: d, Explanation: The class specialization is creation of explicit specialization of a generic class., We have to use template<> constructor for this to work. It works in the same way as with, explicit function specialization., 5. Which is the most significant feature that arises by using template classes?, a) Code readability
Page 142 :
b) Ease in coding, c) Code reusability, d) Modularity in code, View Answer, Answer: c, Explanation: The code reusability is the feature that becomes more powerful with the use of, template classes. You can generate a single code that can be used in variety of programming, situations., advertisement, , 6. A template class defines the form of a class _____________________ it will operate., a) With full specification of the data on which, b) With full specification of the functions on which, c) Without full specification of the data on which, d) Without full specification of the functions on which, View Answer, Answer: c, Explanation: The template classes can accept all types of data types. There is no need to, specify the data on which the class has to operate. Hence it gives us flexibility to code, without worrying about the type of data that might be used in the code., 7. What are the two specializations of I/O template classes in C++?, a) 16-bit character and wide characters, b) 8-bit character and wide characters, c) 32-bit character and locale characters, d) 64-bit characters and locale characters, View Answer, Answer: b, Explanation: The I/O specialization is made with wide character and 8-bit characters. Wide, characters are used to store the characters that might take more than 1 byte of space in, memory or any size that is different from the one that the machine is using., 8. Can typeid() function be used with the object of generic classes?, a) Yes, only if default type is given, b) Yes, always, c) No, generic data can’t be determined, d) No, never possible, View Answer, Answer: b, Explanation: The typeid() function can be used with the objects of generic classes. An, instance of a template class will take the type of data that is being used with it. Hence when, typeid() function is used, the data type would have already been defined and hence we can, get desired result from typeid() function., 9. The _____________ class is a specialization of a more general template class., a) String
Page 143 :
b) Integer, c) Digit, d) Math, View Answer, Answer: a, Explanation: The string class is more specialized. Since the string must be able to store any, kind of data that is given to the string. Hence it needs maximum specialization., 10. How is function overloading different from template class?, a) Overloading is multiple function doing same operation, Template is multiple function, doing different operations, b) Overloading is single function doing different operations, Template is multiple function, doing different operations, c) Overloading is multiple function doing similar operation, Template is multiple function, doing identical operations, d) Overloading is multiple function doing same operation, Template is same function doing, different operations, View Answer, Answer: c, Explanation: The function overloading is multiple functions with similar or different, functionality but generic class functions perform the same task on given different types of, data., advertisement, , 11. What if static members are declared inside template classes?, a) All instances will share the static variable, b) All instances will have their own static variable, c) All the instances will ignore the static variable, d) Program gives compile time error, View Answer, Answer: b, Explanation: The generic class have a special case with static members. Each instance will, have its own static member. The static members are not shared usually., 12. What is the output of following program?, template <typename T>, void test(const T&x), {, static int count = 0;, cout << "x = " << x << " count = " << count, << endl;, ++count;, return;, }, void main(), {, test<int> (2);, test<int>(2);
Page 144 :
test<double>(2.2);, }, , a), x = 2 count = 0, x = 2.2 count = 0, x = 2.2 count = 0, , b), x = 2 count = 0, x = 2 count = 0, x = 2.2 count = 0, advertisement, , c), x = 2 count = 0, x = 2 count = 1, x = 2.2 count = 0, , d), x = 2 count = 0, x = 2 count = 1, x = 2.2 count = 2, , View Answer, Answer: c, Explanation: For each new type, the class will have separate instance. Here two instances will, be created and hence counter for integer goes to 1. And for float value, the count remains 0, for the output., , 13. If template class is defined, is it necessary to use different types of data for each call?, a) No, not necessary, b) No, but at least two types must be there, c) Yes, to make proper use of template, d) Yes, for code efficiency, View Answer, Answer: a, Explanation: It is not necessary to use different type with each call to the generic function., Data may be of same type with each call but still the function works. We don’t consider, other properties like efficiency with this concept because it is made generic to all data type,, hence always works., 14. How many generic types can be given inside a single template class?, a) Only 1, b) Only 3, c) Only 7
Page 145 :
d) As many as required, View Answer, Answer: d, Explanation: There is no restriction on the number of types to be used for making the class, generic. There can be any number of generic types with a single class. Hence giving, flexibility to code with all the data types., 15. Template classes must have at least one static member., a) True, b) False, View Answer, Answer: b, Explanation: There is no mandatory condition to have static members inside template class., Not only template, it is not mandatory to have static members anywhere. We can use them as, required in the code., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Abstract Class, » Next - Object Oriented Programming Questions and Answers – Base Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Abstract Class, Object Oriented Programming Questions and Answers – Base Class, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Collections, 2. Ruby Programming Questions and Answers, 3. C Programming Examples, 4. C# Programming Examples on Inheritance, 5. Python Programming Examples, 6. C# Programming Examples on Interfaces, 7. C++ Programming Examples on STL, 8. Java Programming Examples on String Handling, 9. C Programming Examples on Bitwise Operations, 10. C Programming Examples on Strings, 11. Java Programming Examples on Inheritance
Page 146 :
12. Java Programming Examples on Java.Lang, 13. C# Programming Examples on Delegates, 14. C# Programming Examples on Strings, 15. Java Programming Examples, 16. C++ Questions and Answers, 17. Java Programming Examples on File Handling, 18. Java Programming Examples on Classes, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Base Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Base Class―., 1. Which is most appropriate definition of a base class?, a) It is parent of any of its derived class, b) It is child of one of the parent class, c) It is most basic class of whole program, d) It is class with maximum number of members, View Answer, Answer: a, Explanation: A class which is parent of another class, or from which other classes can be, derived, is known as a base class. It is mandatory that a class must have at least one derived, class to be called as a base class., advertisement, , 2. A base class is also known as _____________ class., a) Basic, b) Inherited, c) Super, d) Sub, View Answer, Answer: c, Explanation: A class which is being derived by other classes, is called as super class. This, concept is clearly used in java as we call the functions of a base class by using the keyword, super as required., 3. An abstract class is always a __________ class., a) Base, b) Derived
Page 147 :
c) Template, d) Nested, View Answer, Answer: a, Explanation: Every abstract class is a base class. It must be so, because the functions which, are not defined inside the abstract class, must be defined in the derived classes. Hence it, becomes a base class., 4. How many base classes can a single class inherit in java?, a) 1, b) 2, c) 3, d) As many as required, View Answer, Answer: a, Explanation: In java, multiple inheritance is not supported, which leads to the fact that a class, can have only 1 parent class if inheritance is used. Only if interfaces are used then the class, can implement more than one base class., 5. How to make a derived class a base class?, a) Change name of the class, b) Use keyword base, c) Make a class derive from it, d) Can’t be done, View Answer, Answer: c, Explanation: Making another class derive from it will make that class as base class. It is not, necessary that we have to write different code for it. If at least one class derives that class, it, becomes the base class for the new class., advertisement, , 6. If a base class is being derived by two other classes, which inheritance will that be called?, a) Single, b) Multiple, c) Multi-level, d) Hierarchical, View Answer, Answer: d, Explanation: When more than one classes are being derived from a single parent class, the, inheritance is known as hierarchical inheritance. This is usually useful when the base class is, higher abstraction of its derived classes., 7. Which among the following must be in a base class?, a) Data members, b) Member functions, c) Access specifiers
Page 148 :
d) Nothing, View Answer, Answer: d, Explanation: Even a class that doesn’t have any members can be a base class. It is not, mandatory to have any member or attribute in base class., 8. Which type of members can’t be accessed in derived classes of a base class?, a) Protected, b) Private, c) Public, d) All can be accessed, View Answer, Answer: b, Explanation: The private members can be accessed only inside the base class. If the class is, derived by other classes. Those members will not be accessible. This concept of OOP is made, to make the members more secure., 9. If a class is enclosing more than one class, than it can be called as base class of those, classes., a) True, b) False, View Answer, Answer: b, Explanation: When a class have more than one nested classes, it is known as enclosing class., It can’t be called as parent or base class since there is no inheritance involved., advertisement, , 10. Base class have ________________ of abstraction., a) Higher degree, b) Lower degree, c) Intermediate, d) Minimum degree, View Answer, Answer: b, Explanation: A base class will have lesser information as compared to those of derived, classes. Since derived classes inherit the base class properties and then add on their own, features, they elaborate more hence have lower degree of abstraction., 11. Always the base class constructors are called ___________ constructor of derived class., a) Before, b) After, c) Along, d) According to priority of, View Answer
Page 149 :
Answer: a, Explanation: When the base class object is created, its constructor will be called for sure. But, if a derived class constructor is called, first base class constructor is called and then derived, class constructor is taken into consideration., 12. Can we call methods of base class using the constructor of the derived class?, a) Yes, always, b) Yes, but not always, c) No, never, d) No, but we can call in some cases, View Answer, Answer: a, Explanation: If the function is defined in the base class, it can always be called from the, constructor of its derived class. Since the constructors are not private, they can be accessed in, derived class even if those are protected., 13. If a base class is inherited from another class and then one class derives it, which, inheritance is shown?, a) Multiple, b) Single, c) Hierarchical, d) Multi-level, View Answer, Answer: d, Explanation: If a base class is inherited from another class, single inheritance is shown. But, when one more class inherits the derived class, this becomes a multi-level inheritance., advertisement, , 14. How many base classes can a single derived class have in C++?, a) 1, b) 2, c) 3, d) As many as required, View Answer, Answer: d, Explanation: This is because C++ allows multiple inheritance. A derived class can have more, than one base class and hence can derive all of their features., 15. If a base class is added with a few new members, its subclass must also be modified., a) True, b) False, View Answer, Answer: b, Explanation: The base class can be added with new members without affecting the, subclasses. This is because the subclasses may get some more features inherited but it
Page 150 :
won’t use them. But the base class will be able to use the new members as would be, required., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Template Class, » Next - Object Oriented Programming Questions and Answers – Derived Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Template Class, Object Oriented Programming Questions and Answers – Derived Class, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Functions, 2. C++ Questions and Answers, 3. C# Questions and Answers, 4. C# Programming Examples on Mathematics, 5. Java Programming Examples on Exception Handling, 6. Java Programming Examples on Collection API, 7. Java Programming Examples on Utility Classes, 8. C# Basic Programming Examples, 9. Java Programming Examples on Collections, 10. Java Programming Examples on Networking, 11. Java Programming Examples on Multithreading, 12. Java Programming Examples on Java.Lang, 13. Programming Questions and Answers, 14. Ruby Programming Questions and Answers, 15. C# Programming Examples, 16. Java Programming Examples, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Inheritance, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Nested Class, advertisement
Page 151 :
Object Oriented Programming Questions, and Answers – Derived Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Derived Class―., 1. Which among the following is best definition of a derived class?, a) A child class, b) A class which inherits one or more classes, c) A class with keyword derived, d) A class with more than one constructor, View Answer, Answer: b, Explanation: Any class which inherits one or more classes is a derived class. The only, condition is it must inherit at least one class in order to be called as a derived class., advertisement, , 2. Which among the following is inherited by a derived class from base class?, a) Data members only, b) Member functions only, c) All the members except private members, d) All the members of base class, View Answer, Answer: c, Explanation: The class inheriting another class, inherits all the data members and member, functions that are not private. This is done to ensure the security features with maximum, flexibility., 3. If there is a derived class in a program, how many classes must be in that program?, a) 1, b) 2, c) 3, d) 4, View Answer, Answer: b, Explanation: If there is a derived class in a program, there must be at least 2 classes in that, program. One is a base class and another derived class. Hence at least 2 classes must be there., 4. Which members can never be accessed in derived class from the base class?, a) Private, b) Protected, c) Public
Page 152 :
d) All except private, View Answer, Answer: d, Explanation: There is no restriction for a derived class to access the members of the base, class until and unless the members are private. Private member are declared so that those, members are not accessible outside the class., 5. How many types of inheritance are supported in C++ for deriving a class?, a) 1, b) 2, c) 3, d) 4, View Answer, Answer: c, Explanation: There are three types of inheritance possible. Private inheritance, protected, inheritance, and public inheritance. The inheritance defines the access specifier to be used, with the inherited members in the derived class., advertisement, , 6. How many derived class can a single base class have?, a) 1, b) 2, c) 3, d) As many are required, View Answer, Answer: d, Explanation: There is no restriction on how many classes can inherit a single base class., Hence there can be as many derived classes as required in a program from a single base class., 7. Which among the following is correct?, a) Friend function of derived class can access non-private members of base class, b) Friend function of base class can access derived class members, c) Friend function of derived class can access members of only derived class, d) Friend function can access private members of base class of a derived class, View Answer, Answer: a, Explanation: The friend function of a class can access the non-private members of base class., The reason behind is that the members of base class gets derived into the derived class and, hence become members of derived class too. Hence a friend function can access all of those., 8. If a class is being derived using more than two base classes, which inheritance will be, used?, a) Single, b) Multi-level, c) Hierarchical
Page 153 :
d) Multiple, View Answer, Answer: d, Explanation: The statement given is the definition of multiple inheritance with respect to the, derived class. The concept can be illustrated with many other samples but the main aspects, are base class and derived class only., 9. Derived class is also known as ______________ class., a) Subclass, b) Small class, c) Big class, d) Noticeable class, View Answer, Answer: a, Explanation: It is just another name given to the derived classes. This is used while denoting, all the derived classes subsequent to a superclass., advertisement, , 10. If class A is derived from another derived class B which is derived from class C, which, class will have maximum level of abstraction?, a) Class A, b) Class B, c) Class C, d) All have the same level of abstraction, View Answer, Answer: c, Explanation: The abstraction level of class C will be maximum. This is because the parent, class have higher level of abstraction. Hence the parent of all other class will have maximum, level of abstraction., 11. If base class is an abstract class then derived class ______________ the undefined, functions., a) Must define, b) Must become another abstract class or define, c) Must become parent class for, d) Must implement 2 definitions of, View Answer, Answer: b, Explanation: The function must be defined in the program which are not defined in the base, class. Hence the class must be defined as abstract of implement the function definition in it., 12. How many classes can be derived from a derived class?, a) Only 1, b) At most 1, c) At least 1
Page 154 :
d) As many as required, View Answer, Answer: d, Explanation: When a class is to be derived from another derived class, the derived class, behaves as a normal base class hence there are no restriction on how many class can be, derived from a derived class. The derived class again behaves as a normal superclass., 13. The members of a derived class can never be derived., a) True, b) False, View Answer, Answer: b, Explanation: This is not true that the members of a derived class can’t be derived. All the, classes are considered to be a normal class when used for derivation. The members can be, derived with respect to their access specifiers., advertisement, , 14. Which feature is not related to the derived classes among the following?, a) Inheritance, b) Encapsulation, c) Run time memory management, d) Compile time function references, View Answer, Answer: c, Explanation: The memory management is the feature that is not necessary for derived classes, that will be a part of whole program. The functions references must be resolved for their, proper use if inheritance is used., 15. Deriving a class in such a way that that the base class members are not available for, further inheritance is known as ___________________, a) Public inheritance, b) Protected inheritance, c) Protected or private inheritance, d) Private inheritance, View Answer, Answer: d, Explanation: The private members of a class can never be derived to another class. When a, class derives another class using private inheritance, all the members become private, members of the derived class. Hence these member won’t be available for further, inheritance., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers.
Page 155 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Base Class, » Next - Object Oriented Programming Questions and Answers – Class Use, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Base Class, Object Oriented Programming Questions and Answers – Class Use, advertisement, advertisement, , Recommended Posts:, 1. Python Programming Examples on Linked Lists, 2. Programming Questions and Answers, 3. C Programming Examples on Linked List, 4. C Programming Examples on Mathematical Functions, 5. C# Programming Examples on Files, 6. Java Programming Examples on Multithreading, 7. Java Programming Examples on File Handling, 8. Java Programming Examples on Collection API, 9. C# Programming Examples on Functions, 10. C# Programming Examples on Exceptions, 11. Java Programming Examples on Networking, 12. Java Programming Examples on Collections, 13. C# Basic Programming Examples, 14. Java Programming Examples on Java.Lang, 15. C# Programming Examples, 16. Java Programming Examples, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Inheritance, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Types of Inheritance, advertisement, , Object Oriented Programming Questions, and Answers – Class Use, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Class Use―., 1. Which among the following is the main characteristic of class?, a) Inheritance
Page 156 :
b) Encapsulation, c) Polymorphism, d) Object creation, View Answer, Answer: b, Explanation: The classes are made to encapsulate the data and properties that are most similar, and can be grouped together inside a single class. This single class can represent all of those, features by creating its instances., advertisement, , 2. To group all the brands of cars, what should be used?, a) Class, b) Structure, c) Function, d) Object, View Answer, Answer: a, Explanation: A class can be used to group all the brands of cars. The Different brands may, have different properties but all will have some common properties like number of wheels, and doors, accessories etc. All of those properties can be grouped into a single class, representing all the cars., 3. If a class have two data members and two functions to add those two numbers and to, subtract them, which among the following is most efficient if the programmer wants to, implement multiplication too?, a) Define a public function which multiplies two numbers, b) Define a public function that returns values of two data members, c) Define a private function which multiplies two numbers, d) Define a private function that returns values of two data members, View Answer, Answer: b, Explanation: The best choice would be to define a public member function that returns the, values of two data members of the class. This way we can implement any operation on those, data members. Also there won’t be any need to modify the program and to add new, functions for each new operation., 4. If a database have to be maintained using OOP, to store the details of each employee in a, company, which would be the best choice among the following?, a) Define a class to store details of each employee, b) Define a structure to store details of each employee, c) Define separate variable for each detail, d) Define a generic type to store string and number details, View Answer, Answer: a, Explanation: A single class can be defined that represents a single employee of a company.
Page 157 :
The specific type of functions that can be applied to specific employees can be put into, another class that is derived from the existing class., 5. Which class represents the most abstracted information?, a) Nested, b) Derived, c) Enclosed, d) Base, View Answer, Answer: d, Explanation: The base classes are the most abstracted part of information. A base class, having many other derived classes would have a bigger overview of all the other derived, classes. Hence the base classes have the most abstract information., advertisement, , 6. Which among the following is an advantage of using classes over structures of C?, a) Functions are restricted, b) Functions can’t be defined, c) Functions can also be encapsulated, d) Functions can have more security, View Answer, Answer: c, Explanation: The functions are also made easy to be encapsulated inside a class. In structures,, only the data members were allowed to be encapsulated. Hence classes can represent an, entity in a better way., 7. Which among the following is a feature of class?, a) Object orientation, b) Procedure orientation, c) Both object and procedure orientation, d) Neither object nor procedure orientation, View Answer, Answer: a, Explanation: Thee use of classes feature the object oriented programming. The OOP concept, can be implemented by using class and their objects. Procedures orientation is not a feature of, OOP., 8. Class is _____________ of an object., a) Basic function definition, b) Detailed description with values, c) Blueprint, d) Set of constant values, View Answer, Answer: c, Explanation: The class is an overview for an object. It contains the basic details map of data, that an object will contain. An object is independent representation of class.
Page 158 :
9. In which case the classes can be used to make the more efficient program?, a) To define a function that is called frequently in a program, b) To structure data that is most similar, c) To group the most similar data and operations, d) To define a blueprint that shows memory location of data, View Answer, Answer: c, Explanation: The classes would be more suitable to use in case where we need to group the, most similar data and operations. The data can be represented as data members of class and, operations as member functions of class. This is indirectly encapsulation feature., advertisement, , 10. What is the use of inbuilt classes?, a) Provide predefined data, b) Provide predefined functions, c) Provide predefined data and functions, d) Provide predeclared data to be overridden, View Answer, Answer: c, Explanation: The data that is constant or is always the same initially for use can be provided, by some inbuilt classes. The functions that are mostly used are also provided by the inbuilt, classes. The data and functions can be used by including the corresponding header file or, library., 11. Which feature is exhibited by the inbuilt classes?, a) Code reusability, b) Code efficiency, c) Code readability, d) Code reusability, efficiency and readability, View Answer, Answer: d, Explanation: The code is reusable as the functions which are already written, can be used, anytime required. The code becomes easier to read. Also, the code is efficient as there is no, need to assign any external code., 12. Why do we use user defined classes?, a) To design a user intended code, b) To model real world objects, c) To design the interfaces, d) To model the functions, View Answer, Answer: b, Explanation: The primitive classes are not sufficient for the programming complex, algorithms. Some user defined classes are required to represent a real world object and to, define a blueprint of what the class should actually contain. The user defined classes are as, per the requirements and need of user.
Page 159 :
13. Why do classes use accessor methods?, a) To make public data accessible to client, b) To make public data private to client, c) To make private data public for whole program, d) To make private data accessible to the client, View Answer, Answer: d, Explanation: The private data of a class is usually not accessible. But the data can be, accessed by the user using accessor functions. These functions allows the user to get the data, stored as private in a class., advertisement, , 14. Why do classes use mutator methods?, a) Allows client to modify the program, b) Allows client to modify/write the private members, c) Allows servers to access all the private data, d) Allows servers to access only protected members, View Answer, Answer: b, Explanation: The client can have rights to access a file and write something to it. This is, mandatory to keep the private data updated. Also it is an advantage over the use of hidden, class members., 15. Which among the following is the most abstract form of class?, a) Cars, b) BMW cars, c) Big cars, d) Small cars, View Answer, Answer: a, Explanation: The most abstract class is class Cars. The class Cars is the most general form of, all other cars. If it is a brand of car, it comes under car. If it is the type of car then also it, comes under Cars., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Derived Class, » Next - Object Oriented Programming Questions and Answers – Inheritance
Page 160 :
Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Derived Class, Object Oriented Programming Questions and Answers – Inheritance, advertisement, advertisement, , Recommended Posts:, 1. Python Programming Examples on Linked Lists, 2. Java Programming Examples on Multithreading, 3. C++ Programming Examples on STL, 4. C Programming Examples on Linked List, 5. C Programming Examples on Stacks & Queues, 6. C Programming Examples, 7. PHP Questions and Answers, 8. R Programming Questions and Answers, 9. Java Programming Examples on Collections, 10. C# Programming Examples, 11. C# Programming Examples on Inheritance, 12. Java Programming Examples on Networking, 13. Programming Questions and Answers, 14. Ruby Programming Questions and Answers, 15. Java Programming Examples on Java.Lang, 16. Java Programming Examples on Classes, 17. Java Programming Examples, 18. C# Programming Examples on Functions, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Inheritance, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Inheritance―., 1. Which among the following best describes the Inheritance?, a) Copying the code already written, b) Using the code already written once, c) Using already defined functions in programming language, d) Using the data and functions into derived segment, View Answer, Answer: d, Explanation: It can only be indicated by using the data and functions that we use in derived
Page 161 :
class, being provided by parent class. Copying code is nowhere similar to this concept, also, using the code already written is same as copying. Using already defined functions is not, inheritance as we are not adding any of our own features., advertisement, , 2. How many basic types of inheritance are provided as OOP feature?, a) 4, b) 3, c) 2, d) 1, View Answer, Answer: a, Explanation: There are basically 4 types of inheritance provided in OOP, namely, single, level, multilevel, multiple and hierarchical inheritance. We can add one more type as Hybrid, inheritance but that is actually the combination any types of inheritance from the 4 basic, ones., 3. Which among the following best defines single level inheritance?, a) A class inheriting a derived class, b) A class inheriting a base class, c) A class inheriting a nested class, d) A class which gets inherited by 2 classes, View Answer, Answer: b, Explanation: A class inheriting a base class defines single level inheritance. Inheriting an, already derived class makes it multilevel inheritance. And if base class is inherited by 2 other, classes, it is multiple inheritance., 4. Which among the following is correct for multiple inheritance?, a) class student{public: int marks;}s; class stream{int total;}; class topper:public student,, public stream{ };, b) class student{int marks;}; class stream{ }; class topper: public student{ };, c) class student{int marks;}; class stream:public student{ };, d) class student{ }; class stream{ }; class topper{ };, View Answer, Answer: a, Explanation: Class topper is getting derived from 2 other classes and hence it is multiple, inheritance. Topper inherits class stream and class student publicly and hence can use its, features. If only few classes are defined, there we are not even using inheritance (as in option, class student{ }; class stream{ }; class topper{ };)., 5. Which programming language doesn’t support multiple inheritance?, a) C++ and Java, b) C and C++, c) Java and SmallTalk, d) Java, View Answer
Page 162 :
Answer: d, Explanation: Java doesn’t support multiple inheritance. But that feature can be, implemented by using the interfaces concept. Multiple inheritance is not supported because, of diamond problem and similar issues., advertisement, , 6. Which among the following is correct for a hierarchical inheritance?, a) Two base classes can be used to be derived into one single class, b) Two or more classes can be derived into one class, c) One base class can be derived into other two derived classes or more, d) One base class can be derived into only 2 classes, View Answer, Answer: c, Explanation: One base class can be derived into the other two derived classes or more. If only, one class gets derived by only 2 other classes, it is also hierarchical inheritance, but it is not a, mandatory condition, because any number of derived classes can be there., 7. Which is the correct syntax of inheritance?, a) class derived_classname : base_classname{ /*define class body*/ };, b) class base_classname : derived_classname{ /*define class body*/ };, c) class derived_classname : access base_classname{ /*define class body*/ };, d) class base_classname :access derived_classname{ /*define class body*/ };, View Answer, Answer: c, Explanation: Firstly, keyword class should come, followed by the derived class name. Colon, is must followed by access in which base class has to be derived, followed by the base class, name. And finally the body of class. Semicolon after the body is also must., 8. Which type of inheritance leads to diamond problem?, a) Single level, b) Multi-level, c) Multiple, d) Hierarchical, View Answer, Answer: c, Explanation: When 2 or more classes inherit the same class using multiple inheritance and, then one more class inherits those two base classes, we get a diamond like structure. Here,, ambiguity arises when same function gets derived into 2 base classes and finally to 3rd level, class because same name functions are being inherited., 9. Which access type data gets derived as private member in derived class?, a) Private, b) Public, c) Protected, d) Protected and Private, View Answer
Page 163 :
Answer: a, Explanation: It is a rule, that when a derived class inherits the base class in private access, mode, all the members of base class gets derived as private members of the derived class., advertisement, , 10. If a base class is inherited in protected access mode then which among the following is, true?, a) Public and Protected members of base class becomes protected members of derived class, b) Only protected members become protected members of derived class, c) Private, Protected and Public all members of base, become private of derived class, d) Only private members of base, become private of derived class, View Answer, Answer: a, Explanation: As the programming language rules apply, all the public and protected members, of base class becomes protected members of derived class in protected access mode. It, can’t be changed because it would hinder the security of data and may add vulnerability, in the program., 11. Members which are not intended to be inherited are declared as ________________, a) Public members, b) Protected members, c) Private members, d) Private or Protected members, View Answer, Answer: c, Explanation: Private access specifier is the most secure access mode. It doesn’t allow, members to be inherited. Even Private inheritance can only inherit protected and public, members., 12. While inheriting a class, if no access mode is specified, then which among the following, is true? (in C++), a) It gets inherited publicly by default, b) It gets inherited protected by default, c) It gets inherited privately by default, d) It is not possible, View Answer, Answer: c, Explanation: If the access mode is not specified during inheritance, the class is inherited, privately by default. This is to ensure the security of data and to maintain OOP features., Hence it is not mandatory to specify the access mode if we want the class to be inherited, privately., 13. If a derived class object is created, which constructor is called first?, a) Base class constructor, b) Derived class constructor, c) Depends on how we call the object
Page 164 :
d) Not possible, View Answer, Answer: a, Explanation: First the base class constructor is invoked. When we create a derived class, object, the system tries to invoke its constructor but the class is derived so first the base class, must be initialized, hence in turn the base class constructor is invoked before the derived, class constructor., advertisement, , 14. The private members of the base class are visible in derived class but are not accessible, directly., a) True, b) False, View Answer, Answer: a, Explanation: Consider that a variable is private in base class and the derived class uses public, inheritance to inherit that class. Now if we also have a global variable of same name as that, of base class private variable, neither the global variable nor the base class private variable, will be accessible from derived class. This is because we can’t have 2 variables with, same name in same local scope. Hence the private members are accessible but not directly., 15. How can you make the private members inheritable?, a) By making their visibility mode as public only, b) By making their visibility mode as protected only, c) By making their visibility mode as private in derived class, d) It can be done both by making the visibility mode public or protected, View Answer, Answer: d, Explanation: It is not mandatory that you have to make the visibility mode either public or, protected. You can do either of those. That will give you permission to inherit the private, members of base class., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Class Use, » Next - Object Oriented Programming Questions and Answers – Types of Inheritance, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Class Use
Page 165 :
Object Oriented Programming Questions and Answers – Types of Inheritance, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on File Handling, 2. Java Programming Examples on Multithreading, 3. C# Programming Examples on Functions, 4. Java Programming Examples on Collection API, 5. C# Questions and Answers, 6. C++ Questions and Answers, 7. Programming Questions and Answers, 8. C# Programming Examples on Exceptions, 9. Java Programming Examples on Networking, 10. C# Programming Examples on LINQ, 11. Java Programming Examples on Collections, 12. Ruby Programming Questions and Answers, 13. C# Basic Programming Examples, 14. C# Programming Examples, 15. Java Programming Examples on Java.Lang, 16. Java Programming Examples on Classes, 17. Java Programming Examples, 18. C# Programming Examples on Inheritance, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Types of Inheritance, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Types of Inheritance―., 1. How many types of inheritance are possible in C++?, a) 2, b) 3, c) 4, d) 5, View Answer, Answer: d, Explanation: There are five types of inheritance that are possible in C++. Single level,, Multilevel, multiple, hierarchical and hybrid. Here we count hybrid also because it sometimes
Page 166 :
can bring up a new form of inheritance, Like inheritance using multiple and hierarchical,, which sometimes results in diamond problem., advertisement, , 2. Which among the following is true?, a) Java supports all types of inheritance, b) Java supports multiple inheritance, c) Java doesn’t support multiple inheritance, d) Java doesn’t support inheritance, View Answer, Answer: c, Explanation: Java doesn’t support multiple inheritance. This is done to avoid the diamond, problem that sometimes arises with inherited functions. Though, multiple inheritance can be, implemented in java using interfaces., 3. Which type of inheritance is illustrated by the following code?, class, class, class, class, class, , student{ public: int marks; };, topper: public student { public: char grade; };, average{ public: int makrs_needed; };, section: public average{ public: char name[10];, overall: public average{ public: int students;, , };, };, , a) Single level, b) Multilevel and single level, c) Hierarchical, d) Hierarchical and single level, View Answer, Answer: c, Explanation: It is hierarchical inheritance and single level inheritance. Since class topper is, inheriting class student, it is single level inheritance. And then average is inherited by section, and overall, so it is hierarchical inheritance. But both of them are separate. Hence it is not, hybrid inheritance., advertisement, , 4. Which among the following best describes multiple inheritance?, a) Two classes being parent of any other classes, b) Three classes being parent of other classes, c) More than one class being parent of other child classes, d) More than one class being parent of single child, View Answer, Answer: d, Explanation: If a class inherits more than one class, it is known as multiple inheritance. This, should not be referred with only two or three classes being inherited. But there must be one, class which inherits more than one class to be called as multiple inheritance., 5. How many types of inheritance can be used at a time in a single program?, a) Any two types
Page 167 :
b) Any three types, c) Any 4 types, d) Any type, any number of times, View Answer, Answer: d, Explanation: Any type of inheritance can be used in any program. There is no rule to use only, few types of inheritance. Only thing that matters is how the classes are inherited and used., 6. Which type of inheritance results in the diamond problem?, a) Single level, b) Hybrid, c) Hierarchical, d) Multilevel, View Answer, Answer: b, Explanation: In diamond problem, hierarchical inheritance is used first, where two different, classes inherit the same class and then in turn a 4th class inherits the two classes which had, inherited the first class. Using more than one type of inheritance here, it is known as hybrid, inheritance., 7. If 6 classes uses single level inheritance with pair classes (3 pairs), which inheritance will, this be called?, a) Single, b) Multiple, c) Hierarchical, d) Multilevel, View Answer, Answer: a, Explanation: Here all the pairs are using single inheritance. And no different pairs are, inheriting same classes. Hence it can’t be called hybrid or multilevel inheritance. You can, say the single inheritance is used 3 times in that program., 8. Which among the following is correct for the following code?, advertisement, class A, {, public : class B, {, public : B(int i): data(i), {, }, int data;, }, };, class C: public A, {, class D:public A::B{ };, };
Page 168 :
a) Multi-level inheritance is used, with nested classes, b) Multiple inheritance is used, with nested classes, c) Single level inheritance is used, with enclosing classes, d) Single level inheritance is used, with both enclosing and nested classes, View Answer, Answer: d, Explanation: Class C is inheriting Class A. Class D is inheriting class B, both are nested., Hence it is single inheritance. For multiple inheritance, class C or D should have inherited, both class A and class B., 9. Which among the following is false?, a) If one class inherits the inherited class in single level inheritance, it is multi-level, inheritance, b) Hybrid inheritance always contains multiple inheritance, c) Hierarchical inheritance involves inheriting same class into more than one classes, d) Hybrid inheritance can involve any types of inheritance together, View Answer, Answer: b, Explanation: It is not necessary to have multiple inheritance in hybrid type. It can have any, type together. This doesn’t have to be of specific type always., 10. If class A has two nested classes B and C. Class D has one nested class E, and have, inherited class A. If E inherits B and C, then ________________, a) It shows multiple inheritance, b) It shows hierarchical inheritance, c) It shows multiple inheritance, d) Multiple inheritance among nested classes, and single level for enclosing classes, View Answer, Answer: d, Explanation: This involves the same concept of inheritance, where the nested classes also, follow the inheritance rules. The Enclosing classes are having single inheritance. Nested, classes involves multiple., 11. In hierarchical inheritance, all the classes involve some kind of inheritance., a) True, b) False, View Answer, Answer: b, Explanation: This is so because few classes might not be involved in any type of inheritance, in whole program whereas other classes might be participating in more than one type of, inheritance at the same time., advertisement, , 12. Which type of inheritance cannot involve private inheritance?, a) Single level, b) Multiple
Page 169 :
c) Hybrid, d) All types can have private inheritance, View Answer, Answer: d, Explanation: This is a common type of inheritance where the protected and public members, of parent class become private members in child class. There is no type which doesn’t, support private inheritance., 13. How many classes can be inherited by a single class in multiple inheritance (C++)?, a) Only 2, b) Only 27, c) Only 1024, d) Any number of classes can be inherited, View Answer, Answer: d, Explanation: Any class can inherit any number of classes. There is no limit defined for the, number of classes being inherited by a single class., 14. How many classes can be inherited by a single class in java?, a) Only 1, b) Only 27, c) Only 255, d) Only 1024, View Answer, Answer: a, Explanation: Since java doesn’t support multiple inheritance, it is not possible for a class, to inherit more than 1 class in java. This is the same case in C# also., 15. If multi-level inheritance is used, First class B inherits class A, then C inherits B and so, on. Till how many classes can this go on?, a) Only till class C, b) Only till class J, c) Only till class Z, d) There is no limit, View Answer, Answer: d, Explanation: In this case, there is no limit. All the classes going on like this will inherit the, members of base class, and hence the upper level inheritance won’t affect the number of, classes that can go on inheriting in this pattern., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers.
Page 170 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Inheritance, » Next - Object Oriented Programming Questions and Answers – Single Level, Inheritance, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Inheritance, Object Oriented Programming Questions and Answers – Single Level Inheritance, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Hard Graph Problems & Algorithms, 2. C# Programming Examples on Functions, 3. Java Programming Examples on Multithreading, 4. Java Programming Examples on Arrays, 5. Ruby Programming Questions and Answers, 6. C# Basic Programming Examples, 7. Java Programming Examples on Utility Classes, 8. Java Programming Examples on File Handling, 9. Java Programming Examples on Event Handling, 10. Java Programming Examples on Java.Lang, 11. Java Programming Examples on Networking, 12. Java Programming Examples on Collection API, 13. Java Programming Examples on Collections, 14. Java Programming Examples on Classes, 15. C# Programming Examples, 16. Java Programming Examples on Exception Handling, 17. Java Programming Examples, 18. Object Oriented Programming Questions and Answers – OOPs Features, 19. Object Oriented Programming Questions and Answers – Private Member Functions, 20. Object Oriented Programming Questions and Answers – Protected Access Specifier, advertisement, , Object Oriented Programming Questions, and Answers – Single Level Inheritance, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Single Level Inheritance―.
Page 171 :
1. Which among the following defines single level inheritance?, a) One base class derives another class, b) One derived class inherits from one base class, c) One base class inherits from one derived class, d) One derived class derives from another derived class, View Answer, Answer: b, Explanation: If only one base class is used to derive only one subclass, it is known as single, level inheritance. The reason of this name is that we inherit the base class to one more level, and stop the inheritance any further., advertisement, , 2. If class A and class B are derived from class C and class D, then ________________, a) Those are 2 pairs of single inheritance, b) That is multilevel inheritance, c) Those is enclosing class, d) Those are all independent classes, View Answer, Answer: a, Explanation: Since class A is derived from class C and then class B is derived from class D,, there are two pairs of classes which shows single inheritance. Those two pairs are, independent of each other though., 3. If single inheritance is used, program will contain ________________, a) At least 2 classes, b) At most 2 classes, c) Exactly 2 classes, d) At most 4 classes, View Answer, Answer: a, Explanation: The program will contain at least 2 classes in the sense of base and derived, classes. At least one base class and one derived class must be there. Types of inheritance, remains the same though., 4. Single level inheritance supports _____________ inheritance., a) Runtime, b) Compile time, c) Multiple inheritance, d) Language independency, View Answer, Answer: a, Explanation: The runtime inheritance is done when object of a class is created to call a, method. At runtime the function is searched if it is in class of object. If not, it will search in, its parent classes and hierarchy for that method., 5. Which method in the code below is single level inherited?
Page 172 :
advertisement, class A, {, protected int a, b;, public: void show(), {, cout<<a<<b;, }, };, class B: public A, {, public: void disp(), {, cout<<a++<<b++;, }, };, class C: private A, public B, {, void avg(), {, cout<<(a+b)/2;, }, };, , a) Class A, b) Class B, c) Class C, d) None, View Answer, Answer: b, Explanation: Class B is using single level inheritance. Class C is using multiple inheritance., And class A is parent of other two classes., 6. If single level inheritance is used and an abstract class is created with some undefined, functions, can its derived class also skip some definitions?, a) Yes, always possible, b) Yes, possible if only one undefined function, c) No, at least 2 undefined functions must be there, d) No, the derived class must implement those methods, View Answer, Answer: d, Explanation: The derived class must implement those methods. This is because the parent, class is abstract and hence will have some undefined functions which has to be defined in, derived classes. Since we are using single level inheritance, if derived class doesn’t, implement those functions then one more class has to be there which will become multi-level, inheritance., 7. Which among the following is false for single level inheritance?, a) There can be more than 2 classes in program to implement single inheritance, b) There can be exactly 2 classes to implement single inheritance in a program, c) There can be more than 2 independent classes involved in single inheritance
Page 173 :
d) The derived class must implement all the abstract method if single inheritance is used, View Answer, Answer: c, Explanation: If more than 2 independent classes are involved to implement the single level, inheritance, it won’t be possible as there must be only one child and one parent class and, none other related class., 8. Which concept will result in derived class with more features (consider maximum 3, classes)?, a) Single inheritance, b) Multiple inheritance, c) Multilevel inheritance, d) Hierarchical inheritance, View Answer, Answer: b, Explanation: If single inheritance is used then only feature of a single class are inherited, and, if multilevel inheritance is used, the 2nd class might have use private inheritance. Hence only, multiple inheritance can result in derived class with more features. This is not mandatory but, in a case if we consider same number of features in each class, it will result the same., advertisement, , 9. Single level inheritance is safer than _____________, a) Multiple inheritance, b) Interfaces, c) Implementations, d) Extensions, View Answer, Answer: a, Explanation: Interfaces also represent a way of inheritance but is a wide word to decide, which inheritance we are talking about in it, hence can’t be considered. Implementation, and extensions also doesn’t match that level of specific idea. And multiple inheritance not, so safe as it might result in some ambiguity., 10. Which language doesn’t support single level inheritance?, a) Java, b) C++, c) Kotlin, d) All languages support it, View Answer, Answer: d, Explanation: All the languages support single level inheritance. Since any class can inherit, other classes as required, if single level inheritance was not allowed it would result in failing, a lot of features of OOP., 11. What is the output of the following program?
Page 174 :
class A, {, protected: int a,b;, public: void disp(), {, cout<<a<<b;, }, };, class B:public A, {, int x,y;, };, , a) Garbage value, b) Compile time error, c) Runtime error, d) Runs but gives random values as output, View Answer, Answer: b, Explanation: The compiler doesn’t find the main function and hence will throw an error, main() missing. This program is using single level inheritance but the program is incomplete., Every program must implement main function., advertisement, , 12. What is the output of the following program?, class A, {, float sal=40000;, }, class B extends A, {, int salBonus=10000;, public static void main(String args[]), {, B p=new B();, System.out.println("B salary is:"+p.sal);, System.out.println("Bonus of B is:"+p.bonus);, }, }, , a), B salary is: 4000.0, Bonus of B is: 10000, , b), B salary is 10000, Bonus of B is: 4000.0, , c) Compile time error, d) Runtime error, View Answer
Page 175 :
Answer: a, Explanation: The program gives output as in option a. The program have used single level, inheritance and hence have access to the parent class methods and variables. This program, simply prints the value from parent class and from the child class., 13. Single level inheritance will be best for___________, a) Inheriting a class which performs all the calculations, b) Inheriting a class which can print all the calculation results, c) Inheriting a class which can perform and print all calculations, d) Inheriting all the classes for different calculations, View Answer, Answer: b, Explanation: Inheriting a class which can perform the most common task will be more, efficient. If class which can perform all the calculations is inherited then there won’t be, any problem to print the result too. But if a class which can do the most common task for all, the other tasks, it will make real use of inheritance., 14. Which constructor will be called first from the classes involved in single inheritance from, object of derived class?, a) Base class constructor, b) Derived class constructor, c) Both class constructors at a time, d) Runtime error, View Answer, Answer: a, Explanation: The base class constructor will be called first from the object of derived class, constructor. When the derived class members are to be initialized and allocated memory, the, base class members should also be confirmed with the memory allocation., 15. If base class contains 2 nested classes, will it be possible to implement single level, inheritance?, a) Yes, always, b) Yes, only if derived class also have nested classes, c) No, it will use more than 2 classes which is wrong, d) No, never, View Answer, Answer: a, Explanation: The nested classes are also members of a class. They behave as a used defined, data type with some methods implementation. So the inheritance will be as usual with the, nested classes being member of base class and of derived class if not private., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers.
Page 176 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Types of Inheritance, » Next - Object Oriented Programming Questions and Answers – Multilevel Inheritance, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Types of Inheritance, Object Oriented Programming Questions and Answers – Multilevel Inheritance, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Networking, 2. C Programming Examples on Linked List, 3. Python Programming Examples on Graphs, 4. Java Programming Examples on Collections, 5. Python Programming Examples on Linked Lists, 6. C# Programming Examples on Functions, 7. C++ Programming Examples on Data-Structures, 8. Java Programming Examples on Multithreading, 9. C Programming Examples on Data-Structures, 10. C Programming Examples on Stacks & Queues, 11. Python Programming Examples on Stacks & Queues, 12. C# Basic Programming Examples, 13. C# Programming Examples, 14. Java Programming Examples, 15. Java Programming Examples on Classes, 16. C++ Programming Examples on STL, 17. Java Programming Examples on Collection API, 18. Object Oriented Programming Questions and Answers, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Access Specifiers, advertisement, , Object Oriented Programming Questions, and Answers – Multilevel Inheritance, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Multilevel Inheritance―., 1. Which among the following best defines multilevel inheritance?, a) A class derived from another derived class
Page 177 :
b) Classes being derived from other derived classes, c) Continuing single level inheritance, d) Class which have more than one parent, View Answer, Answer: b, Explanation: Only if the class is being derived from other derived class, it can be called as, multilevel inheritance. If a class is derived from another class, it is single level inheritance., There must be more than one level of inheritance., advertisement, , 2. If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class, constructor will be called first if the object of E or D is created?, a) A, b) B, c) C, d) A and B, View Answer, Answer: a, Explanation: A is parent of all other classes indirectly. Since A is parent of B and B is parent, of C and so on till E. Class A constructor will be called first always., 3. If there are 3 classes. Class C is derived from class B and B is derived from A, Which class, destructor will be called at last if object of C is destroyed., a) A, b) B, c) C, d) All together, View Answer, Answer: a, Explanation: The destructors are called in the reverse order of the constructors being called., Hence in multilevel inheritance, the constructors are created from parent to child, which leads, to destruction from child to parent. Hence class A destructor will be called at last., 4. Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?, a) Class at 1st level, b) Class 2nd last level, c) Class at 5th level, d) All with same abstraction, View Answer, Answer: a, Explanation: The class with highest degree of abstraction will be the class at the 1st level., You can look at a simple example like, a CAR is more abstract than SPORTS CAR class., The level of abstraction decrease with each level as more details comes out., 5. If all the classes use private inheritance in multilevel inheritance then ______________, a) It will not be called multilevel inheritance
Page 178 :
b) Each class can access only non-private members of its parent, c) Each subsequent class can access all members of previous level parent classes, d) None of the members will be available to any other class, View Answer, Answer: b, Explanation: The classes will be able to access only the non-private members of its parent, class. The classes are using private inheritance, hence all the members of the parent class, become private in the derived class. In turn those won’t be allowed for further inheritance, or direct access outside the class., advertisement, , 6. Multilevel inheritance allows _________________ in the program., a) Only 7 levels of inheritance, b) At least 7 levels of inheritance, c) At most 16 levels of inheritance, d) As many levels of inheritance as required, View Answer, Answer: d, Explanation: The multilevel inheritance allows any number of levels of inheritance. This is, the maximum flexibility feature to make the members available to all the new classes and to, add their own functionalities. The code reusability is used too., 7. What is the minimum number of levels for a implementing multilevel inheritance?, a) 1, b) 2, c) 3, d) 4, View Answer, Answer: c, Explanation: There must be at least 3 levels of inheritance. Otherwise if less, it will be single, level inheritance or would have got no inheritance implemented. There must be a derived, class from which another class is derived., 8. In multilevel inheritance one class inherits _______________, a) Only one class, b) More than one class, c) At least one class, d) As many classes as required, View Answer, Answer: a, Explanation: The classes inherit only from one class. This continues as each class inherits, only one class. There should not be any class that inherits from two or more classes or which, have more than one subclass., 9. All the classes must have all the members declared private to implement multilevel, inheritance.
Page 179 :
a) True, b) False, View Answer, Answer: b, Explanation: There is no mandatory rule to make the members private for multilevel, inheritance. Moreover, if all the classes have only the private members then there won’t, be any member to get inherited. Hence the working will be of no use., 10. Can abstract classes be used in multilevel inheritance?, a) Yes, always, b) Yes, only one abstract class, c) No, abstract class doesn’t have constructors, d) No, never, View Answer, Answer: a, Explanation: The abstract classes can always be used in multilevel inheritance. The only, condition that may arise is that all the undefined functions must be defined in subclasses., There must not be any undefined function., advertisement, , 11. How many abstract classes can be used in multilevel inheritance?, a) Only 1, b) Only 2, c) At least one less than number of levels, d) Can’t be used, View Answer, Answer: c, Explanation: At least one class must implement all the undefined functions. Hence there must, be at least one class which is not abstract. That is at least one less than number of levels., 12. If all the classes used parameterized constructors and no default constructor then, ___________, a) The object of lower level classes can’t be created, b) Object of lower level classes must call parent class constructors explicitly, c) Object of lower level classes must define all the default constructors, d) Only object of first class can be created, which is first parent, View Answer, Answer: b, Explanation: Each class constructor must be called before creating the object of any subclass., Hence it will be mandatory to call the constructors of parent classes explicitly with, parameters. This will make all the previous class member be initialized and then the class in, use will be able to create the object., 13. In multilevel inheritance, which is the most significant feature of OOP used?, a) Code readability, b) Flexibility
Page 180 :
c) Code reusability, d) Code efficiency, View Answer, Answer: c, Explanation: The classes using multilevel inheritance will use the code in all the subsequent, subclasses if available. Hence the most significant feature among the options given is code, reusability. This feature is generally intended to use the data values and reuse the redundant, functions., 14. Does following code show multiple inheritance?, class A, {, int a;, };, class B, {, int b;, };, class C:public A, public B, {, int c;, };, class D:public C, {, int d;, };, , a) Yes, class C and class D, b) Yes, All together it’s multilevel, c) No, 4 classes are used, d) No, multiple inheritance is used with class A, B and C, View Answer, Answer: d, Explanation: Since multiple inheritance is used to derive class C and then class D is derived, from class C. This is not multilevel inheritance. The classes should derive from single class., This is actually hybrid inheritance., advertisement, , 15. Is it compulsory for all the classes in multilevel inheritance to have constructors defined, explicitly if only last derived class object is created?, a) Yes, always, b) Yes, to initialize the members, c) No, it not necessary, d) No, Constructor must not be defined, View Answer, Answer: c, Explanation: It’s not mandatory to define the constructors explicitly. Default constructor
Page 181 :
will always be provided by the compiler itself if none another constructor is defined in those, classes. If explicit default constructor is defined it will be used., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Single Level, Inheritance, » Next - Object Oriented Programming Questions and Answers – Multiple Inheritance, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Single Level Inheritance, Object Oriented Programming Questions and Answers – Multiple Inheritance, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on LINQ, 2. Java Programming Examples on File Handling, 3. C# Programming Examples on Mathematics, 4. C# Programming Examples on Functions, 5. C++ Questions and Answers, 6. C# Basic Programming Examples, 7. C# Questions and Answers, 8. Ruby Programming Questions and Answers, 9. Java Programming Examples on Exception Handling, 10. Java Programming Examples on Utility Classes, 11. Java Programming Examples on Collections, 12. Java Programming Examples on Multithreading, 13. Java Programming Examples on Networking, 14. Java Programming Examples on Java.Lang, 15. C# Programming Examples, 16. Java Programming Examples, 17. Java Programming Examples on Classes, 18. Object Oriented Programming Questions and Answers – Data Members, 19. Object Oriented Programming Questions and Answers – Virtual Functions, 20. Object Oriented Programming Questions and Answers – Copy Constructor, advertisement
Page 182 :
Object Oriented Programming Questions, and Answers – Multiple Inheritance, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Multiple Inheritance―., 1. Multiple inheritance is ____________________, a) When a class is derived from another class, b) When a class is derived from two or more classes, c) When a class is derived from other two derived classes, d) When a class is derived from exactly one class, View Answer, Answer: b, Explanation: The multiple inheritance is used when a class is being derived using two base, classes or more. This way a single class can have features of more than one classes inherited, into a single unit. This lets us combine two class members into a single class., advertisement, , 2. Which problem arises due to multiple inheritance, if hierarchical inheritance is used, previously for its base classes?, a) Diamond, b) Circle, c) Triangle, d) Loop, View Answer, Answer: a, Explanation: The diamond problem arises when multiple inheritance is used. This problem, arises because the same name member functions get derived into a single class. Which in turn, creates ambiguity in calling those methods., 3. How many classes should a program contain to implement the multiple inheritance?, a) Only 1, b) At least 1, c) At least 3, d) Exactly 3, View Answer, Answer: c, Explanation: For the implementation of multiple inheritance, there must be at least 3 classes, in a program. At least 2 base classes and one class to inherit those two classes. If lesser, it, becomes single level inheritance.
Page 183 :
4. Which programming language restricts the use of multiple inheritance?, a) C++, b) PHP, c) SmallTalk, d) Java, View Answer, Answer: d, Explanation: Java doesn’t allow use of multiple inheritance with classes. But this can be, done by using the interfaces. This is more secure and unambiguous way to implement, multiple inheritance., 5. Is it possible to have all the abstract classes as base classes of a derived class from those?, a) Yes, always, b) Yes, only if derived class implements all the methods, c) No, because abstract classes doesn’t have constructors, d) No, never, View Answer, Answer: b, Explanation: The condition for abstract class applies same here too. All the undefined, functions must be defined. Hence all the base classes can be abstract but derived class must, implement all those undefined functions., advertisement, , 6. If class A inherits class B and class C as “class A: public class B, public class C {//, class body ;}; ―, which class constructor will be called first?, a) Class A, b) Class B, c) Class C, d) All together, View Answer, Answer: b, Explanation: The constructors of parent class will be called first. In that, the constructor of, the classes will be called in the same sequence as that mentioned in class definition, inheritance. Since class B is mentioned first for inheritance, its constructor will be called first., 7. Why does diamond problem arise due to multiple inheritance?, a) Methods with same name creates ambiguity and conflict, b) Methods inherited from the superclass may conflict, c) Derived class gets overloaded with more than two class methods, d) Derived class can’t distinguish the owner class of any derived method, View Answer, Answer: a, Explanation: All the derived classes can distinguish the base class members, but if a method, is being inherited to the base classes from another class which again gets inherited into same, class (diamond shape), that may create conflict in using the function from two available.
Page 184 :
8. How many base classes can a derived class have which is implementing multiple, inheritance?, a) Only 2, b) At least 2, c) At most 2, d) As many as required, View Answer, Answer: d, Explanation: The classes can derive from as many classes as required since the multiple, inheritance feature is made to combine or group together the functions that are from different, classes. This make the derived class stronger in terms of its flexibility., 9. How to overcome diamond problem?, a) Using alias name, b) Using seperate derived class, c) Using virtual keyword with same name function, d) Can’t be done, View Answer, Answer: c, Explanation: To overcome the ambiguity and conflict we can use keyword virtual. This will, help us to differentiate the functions with same name that came to last derived class in, diamond problem., advertisement, , 10. When multiple inheritance is used, which class object should be used in order to access, all the available members of parent and derived class?, a) Derived class object, b) Parent class objects, c) Use Abstract derived class, d) Derive a class from derived class, View Answer, Answer: a, Explanation: The derived class object can access all of its own members. It can also access, the available members of the parent classes, because the members are derived into the, derived class., 11. If all the members of all the base classes are private then _____________, a) There won’t be any use of multiple inheritance, b) It will make those members public, c) Derived class can still access them in multiple inheritance, d) Compile time error, View Answer, Answer: a, Explanation: The derived class will not be able to access any members of the base classes., Since private member’s are not inheritable. It leads to no use of multiple inheritance.
Page 185 :
12. Is it compulsory to have constructor for all the classes involved in multiple inheritance?, a) Yes, always, b) Yes, only if no abstract class is involved, c) No, only classes being used should have a constructor, d) No, they must not contain constructors, View Answer, Answer: b, Explanation: The constructors must be defined in every class. If class is abstract, it won’t, have any constructor but other classes must have constructor. Either implicit or explicit., 13. If a class contains 2 nested class and is being inherited by another class, will there be any, multiple inheritance?, a) No, only single level inheritance is used, b) No, only multilevel inheritance is used, c) Yes, because 3 classes are involved, d) Yes, because more than 1 classes are being derived, View Answer, Answer: a, Explanation: When a class having nested classes is being derived into another class. It, indirectly means a simple class is being inherited to another class. This is single level, inheritance., advertisement, , 14. Which members can’t be accessed in derived class in multiple inheritance?, a) Private members of base, b) Public members of base, c) Protected members of base, d) All the members of base, View Answer, Answer: a, Explanation: The private member’s are available for only the class containing those, members. Derived classes will have access to protected and public members only., 15. Can the derived class be made abstract if multiple inheritance is used?, a) No, because other classes must be abstract too, b) Yes, if all the functions are implemented, c) Yes, if all the methods are predefined, d) No, since constructors won’t be there, View Answer, Answer: d, Explanation: The derived class must not be abstract. This is because the abstract classes, doesn’t have constructor and hence we won’t be having the capability to have, instances. This will restrict the use of multiple inheritance., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs).
Page 186 :
To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Multilevel Inheritance, » Next - Object Oriented Programming Questions and Answers – Hierarchical, Inheritance, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Multilevel Inheritance, Object Oriented Programming Questions and Answers – Hierarchical Inheritance, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Networking, 2. Java Questions and Answers, 3. Java Programming Examples on Event Handling, 4. Java Programming Examples on Mathematical Functions, 5. C# Programming Examples on Files, 6. Java Programming Examples on Multithreading, 7. Java Programming Examples on Utility Classes, 8. C++ Questions and Answers, 9. Java Programming Examples on Collections, 10. C# Questions and Answers, 11. C# Programming Examples on Functions, 12. Java Programming Examples on Java.Lang, 13. Ruby Programming Questions and Answers, 14. C# Basic Programming Examples, 15. C# Programming Examples, 16. Java Programming Examples, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Inheritance, 19. Object Oriented Programming Questions and Answers – Data Members, 20. Object Oriented Programming Questions and Answers – Object Use, advertisement, , Object Oriented Programming Questions, and Answers – Hierarchical Inheritance, « Prev, Next »
Page 187 :
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Hierarchical Inheritance―., 1. Which among the following is best to define hierarchical inheritance?, a) More than one classes being derived from one class, b) More than 2 classes being derived from single base class, c) At most 2 classes being derived from single base class, d) At most 1 class derived from another class, View Answer, Answer: a, Explanation: When two or more classes get derived from a single base class, it is known as, hierarchical inheritance. This gives us freedom to use same code with different scopes and, flexibility into different classes., advertisement, , 2. Do members of base class gets divided among all of its child classes?, a) Yes, equally, b) Yes, depending on type of inheritance, c) No, it’s doesn’t get divided, d) No, it may or may not get divided, View Answer, Answer: c, Explanation: The class members doesn’t get divided among the child classes. All the, members get derived to each of the subclasses as whole. The only restriction is from the, access specifiers used., 3. Each class can inherit the base class ________________, a) Independently using any inheritance, b) Independently with private inheritance only, c) With same type of inheritance, d) With each class using different inheritance only, View Answer, Answer: a, Explanation: The classes can inherit the base class using any type of inheritance. There is no, mandatory condition to use same private,public or protected inheritance only., 4. How many classes must be there to implement hierarchical inheritance?, a) Exactly 3, b) At least 3, c) At most 3, d) At least 1, View Answer, Answer: b, Explanation: At least 3 classes must be there. Two derived classes and one base class. This, lets us implement two classes that have common characteristics from base class.
Page 188 :
5. Base class _______________, a) Can be made abstract, b) Can’t be made abstract, c) Must be abstract, d) If made abstract, compile time error, View Answer, Answer: a, Explanation: The base class may or may not be declared abstract. It depends on the need of, program. If it is made abstract, it can contain undefined functions too. In turn, those functions, will have to be implemented by each of the derived classes., advertisement, , 6. Which access specifiers should be used so that all the derived classes restrict further, inheritance of base class members?, a) Private, b) Public, c) Protected, d) Any inheritance type can be used, View Answer, Answer: a, Explanation: All the derived classes must use private inheritance. This will make the, members of base class private in derived classes. Hence none of the members of base class, will be available for further inheritance., 7. Which class uses hierarchical inheritance in following code?, class A, {, int a;, };, class B:class A, {, int b;, };, class C:class A,class B, {, int c;, };, class D:class A, {, int d;, };, , a) Class A, B, C, b) Class B, C, D, c) Class A, C, D, d) Class D, A, B, View Answer
Page 189 :
Answer: d, Explanation: Class A is base class and B and D are derived classes. If class C is considered, it, shows hybrid inheritance, involving single level and multiple inheritance., 8. Which among the following is correct for following code?, abstract class A, {, public Int a;, public void disp();, };, class B:public A, {, public: void dis(), {, court<<a;, }, };, class C:private A, {, public void incr(), {, a++;, }, }, void main(), {, B b.disp();, }, , advertisement, , a) Compile time error, b) Runtime error, c) Program runs and o/p is 0, d) Program runs and o/p is garbage value, View Answer, Answer: a, Explanation: The derived class D have not implemented the undefined function. Here the, main concept involves hierarchical inheritance with abstract base class., 9. How many classes can be derived from the base class using hierarchical inheritance?, a) As many as required, b) Only 7, c) Only 3, d) Up to 127, View Answer, Answer: a, Explanation: The number of classes that can be derived from a base class doesn’t have, any restriction and hence will be able to derive as many classes as required. This feature, gives more flexibility and code reusability.
Page 190 :
10. If one class have derived the base class privately then another class can’t derive the, base class publically., a) True, b) False, View Answer, Answer: b, Explanation: The classes are independent and can access the base class and inherit it in, whichever way it is required. The classes can use the base base class members privately or, publically maintaining the security of data and methods., 11. Which among the following is true?, a) Hierarchical inheritance is subset of multiple inheritances, b) Hierarchical inheritance is strongest inheritance type, c) Hierarchical inheritance uses only 2 classes for implementation, d) Hierarchical inheritance allows inheritance of common features to more than one class, View Answer, Answer: d, Explanation: Hierarchical inheritance is used to make all the inherited classes have some, common features obtained from a single base class. This allows all the classes to maintain a, group or to be classified under one class., advertisement, , 12. Hierarchical inheritance can be a subset of _________________, a) Hybrid inheritance, b) Multiple inheritance, c) Single level inheritance, d) Multilevel inheritance, View Answer, Answer: a, Explanation: When we use hybrid inheritance, it can contain any type of inheritance or, combination or more than two types. Hence it may contain Hierarchical inheritance too,, hence it can be subset of hybrid inheritance., 13. Which type of inheritance is most suitable for inheriting Same syllabus into different, colleges with different streams?, a) Multiple, b) Single, c) Hierarchical, d) Multilevel, View Answer, Answer: c, Explanation: When hierarchical inheritance is used, the common syllabus can be adopted into, different college classes where the same syllabus is applicable. For changing the syllabus, only the details of base class will have to changed.
Page 191 :
14. Which class constructor is called first when an object of derived class is created?, a) Base class constructor, b) Derived class constructor, c) Firstly created derived class constructor, d) Last created derived class constructor, View Answer, Answer: a, Explanation: The base class must be initialised first hence the constructor of base class is, called first. This makes everything ready for the new object being created., 15. All the derived classes can access only a few members of base class that other derived, classes can’t access at same time, in hierarchical inheritance., a) True, b) False, View Answer, Answer: b, Explanation: The derived classes have full access to all the non private member’s of base, class. Every derived class have equal access, none of the class can have special access to, specific members of base class in general cases., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Multiple Inheritance, » Next - Object Oriented Programming Questions and Answers – Hybrid Inheritance, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Multiple Inheritance, Object Oriented Programming Questions and Answers – Hybrid Inheritance, advertisement, advertisement, , Recommended Posts:, 1., 2., 3., 4., 5., 6., 7., , Java Programming Examples on Exception Handling, C# Programming Examples on Exceptions, Java Programming Examples on Event Handling, Java Programming Examples on Networking, Java Programming Examples on Multithreading, Java Programming Examples on File Handling, Java Programming Examples on Utility Classes
Page 192 :
8. Ruby Programming Questions and Answers, 9. C++ Questions and Answers, 10. C# Programming Examples on Functions, 11. C# Questions and Answers, 12. Java Programming Examples on Collections, 13. C# Basic Programming Examples, 14. Java Programming Examples on Java.Lang, 15. C# Programming Examples, 16. Java Programming Examples, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Inheritance, 19. Object Oriented Programming Questions and Answers – Data Members, 20. Object Oriented Programming Questions and Answers – Class Use, advertisement, , Object Oriented Programming Questions, and Answers – Hybrid Inheritance, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Hybrid Inheritance―., 1. Which among the following best defines the hybrid inheritance?, a) Combination of two or more inheritance types, b) Combination of same type of inheritance, c) Inheritance of more than 7 classes, d) Inheritance involving all the types of inheritance, View Answer, Answer: a, Explanation: When more than one type of inheritance are used together, it results in new type, of inheritance which is in general known as hybrid inheritance. This may of may not have, better capabilities., advertisement, , 2. How many types of inheritance should be used for hybrid?, a) Only 1, b) At least 2, c) At most two, d) Always more than 2, View Answer, Answer: b, Explanation: There must be combination of at least 2 types of inheritance. The inheritance, should be of different type.
Page 193 :
3. If single inheritance is used with class A and B. A is base class. Then class C, D and E, where C is base class and D is derived from C, then E is derived from D. Class C is made to, inherit from class B. Which is the resultant type?, a) Single level, b) Multilevel, c) Hybrid, d) Multiple, View Answer, Answer: b, Explanation: The statement represents multilevel inheritance. It is not hybrid since looking at, complete idea, one can’t differentiate whether two type of inheritance are used. Hence it, is multilevel inheritance., 4. Diamond problem includes ____________________ hybrid inheritance., a) Hierarchical and Multiple, b) Hierarchical and Hierarchical, c) Multiple and Multilevel, d) Single, Hierarchical and Multiple, View Answer, Answer:a, Explanation: The diamond problem arises when more than one classes are derived from one, class and then those classes are used to derive single clas. Resulting in ambiguity of same, functions from each class., 5. If __________________ inheritance is done continuously, it is similar to tree structure., a) Hierarchical, b) Multiple, c) Multilevel, d) Hierarchical and Multiple, View Answer, Answer: a, Explanation: Hierarchical inheritance is deriving more than one classes from a base class, it it, is done continuously and subsequently, it results forming a tree like structure of classes being, linked., advertisement, , 6. Which amongst the following is true for hybrid inheritance?, a) Constructor calls are in reverse, b) Constructor calls are priority based, c) Constructor of only derived class is called, d) Constructor calls are usual, View Answer, Answer: d, Explanation: The constructors will be called in usual way. First the parent class Constructor, and then the derived class Constructors. This is done to initialise all the members properly.
Page 194 :
7. Which type of inheritance must be used so that the resultant is hybrid?, a) Multiple, b) Hierarchical, c) Multilevel, d) None, View Answer, Answer: d, Explanation: The use of any specific type is not necessary. Though the final structure should, not be the same, it should represent more than one type of inheritance if class diagram is, drawn., 8. The private member’s are made public to all the classes in inheritance., a) True, b) False, View Answer, Answer: b, Explanation: The private member’s scope can’t be changed and those can never be, accessed in other classes. Only the class containing private member’s can access its own, members., 9. If hierarchical inheritance requires to inherit more than one class to single class, which, syntax is correct? (A, B, C are class names), a) hierarchical class A: public B, public C, b) multiple class A: public B, public C, c) many class A: public B, public C, d) class A: public B, public C, View Answer, Answer: d, Explanation: The syntax is as same as declaration of other classes. There is no specific, keyword defined for using hybrid inheritance in programming. Only thing is to specify the, class name separated by commas., advertisement, , 10. What is the maximum number of classes allowed in hybrid inheritance?, a) 7, b) 127, c) 255, d) As many as required, View Answer, Answer: d, Explanation: The classes in any type of inheritance can inherit as many classes as required., The only condition that may arise is memory management. The classes can inherit most of, the features from more than one class., 11. What is the minimum number of classes to be there in a program implementing hybrid, inheritance?
Page 195 :
a) 2, b) 3, c) 4, d) No limit, View Answer, Answer: d, Explanation: The answer is no limit. There is no condition defined for limit of classes that has, to be used in hybrid. Though you must have at least 4 classes so that one set of multiple or, hierarchical inheritance is there and one more class to use single level inheritance., 12. If object of lowest level class is created (last derived class) ________________ of its, parent class constructors are called., a) Few, b) All, c) Only parent and parent, d) Base and Derived, View Answer, Answer: c, Explanation: When derived class object is created, all of its successor parent classes, constructors are called. Constructor of all the connected classes is not created. Since the, parent members have to be initialised, but other derived classes are not needed., 13. If hybrid inheritance is used, it mostly shows _______________ feature of OOP., a) Flexibility, b) Reusability, c) Efficiency, d) Code readability, View Answer, Answer: b, Explanation: The code is reusable in most of the classes and the data becomes more linked to, other classes. Other features are also exhibited, but the code reusability is used the most., Code readability becomes relatively less. Flexibility increases but it depends on how the, hybrid inheritance is used., advertisement, , 14. The sequence of destructors being called while using hybrid inheritance is ____________, a) Reverse of constructors being called, b) Reverse of classes being made, c) Reverse of objects being created, d) Reverse of code calling objects, View Answer, Answer: a, Explanation: The destructors are always called in reverse order of constructors being called, always. The type of inheritance doesn’t matter. The only important concept is the, sequence of classes being inherited.
Page 196 :
15. Overloading operators are possible only by using hybrid inheritance., a) True, b) False, View Answer, Answer: b, Explanation: The overloading concept is not related to the types of inheritance being used., Overloading operators can be done without using inheritance. You don’t even have to use, more than one class for operator overloading., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Hierarchical Inheritance, » Next - Object Oriented Programming Questions and Answers – Virtual Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Hierarchical Inheritance, Object Oriented Programming Questions and Answers – Virtual Functions, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Utility Classes, 2. C Programming Examples on Linked List, 3. C# Programming Examples on Arrays, 4. C# Programming Examples on Mathematics, 5. Java Programming Examples on Exception Handling, 6. C++ Questions and Answers, 7. C# Basic Programming Examples, 8. C# Programming Examples on Functions, 9. Ruby Programming Questions and Answers, 10. Java Programming Examples on Multithreading, 11. C# Questions and Answers, 12. Java Programming Examples on Networking, 13. Java Programming Examples on Collections, 14. Java Programming Examples on Java.Lang, 15. Java Programming Examples, 16. C# Programming Examples, 17. Java Programming Examples on Classes, 18. Object Oriented Programming Questions and Answers – Abstract Class, 19. Object Oriented Programming Questions and Answers – Classes
Page 197 :
20. Object Oriented Programming Questions and Answers – Types of Constructors, advertisement, , Object Oriented Programming Questions, and Answers – Virtual Functions, « Prev, Next », , This set of Object Oriented Programming Questions and Answers for Entrance exams focuses, on “Virtual Functions―., 1. Virtual function is ______ class function which expected to be redefined in ______ class,, so that when reference is made to derived class object using pointer then we can call virtual, function to execute ________ class definition version., a) Base, derived, derived, b) Derived, Derived, Derived, c) Base, derived, base, d) Base, base, derived, View Answer, Answer: a, Explanation: The functions which may give rise to ambiguity due to inheritance, can be, declared virtual. So that whenever derived class object is referred using pointer or reference, to the base class methods, we can still call the derived class methods using virtual function., Hence this differentiates those methods from each other., advertisement, , 2. What does a virtual function ensure for an object, among the following?, a) Correct method is called, regardless of the class defining it, b) Correct method is called, regardless of the object being called, c) Correct method is called, regardless of the type of reference used for function call, d) Correct method is called, regardless of the type of function being called by objects, View Answer, Answer: c, Explanation: It is property of the virtual function and one of their main use. Its use ensure that, the correct method is called even though it is been called from different pointer or references., This also decreases chance of mistakes in program., 3. Virtual functions are mainly used to achieve _____________, a) Compile time polymorphism, b) Interpreter polymorphism, c) Runtime polymorphism, d) Functions code polymorphism, View Answer
Page 198 :
Answer: c, Explanation: It is used to achieve runtime polymorphism. The functions which are inherited, and overridden, so at runtime the correct function is executed. The correct function call is, made from the intended class., 4. Which keyword is used to declare virtual functions?, a) virtual, b) virt, c) anonymous, d) virtually, View Answer, Answer: a, Explanation: The virtual keyword is used to declare virtual functions. Anonymous keyword is, used with classes and have a different meaning. The virtual functions are used to call the, intended function of the derived class., 5. Where the virtual function should be defined?, a) Twice in base class, b) Derived class, c) Base class and derived class, d) Base class, View Answer, Answer: d, Explanation: The virtual function should be declared in base class. So that when the derived, class inherits from the base class, the functions can be differentiated from the one in base, class and another in derived class., advertisement, , 6. The resolving of virtual functions is done at ______________, a) Compile time, b) Interpret time, c) Runtime, d) Writing source code, View Answer, Answer: c, Explanation: The resolving of virtual functions that are to be called is done at run time. The, base class and the derived classes may contain different definitions and different variables, so, all these things are resolved at run time and decided which function is to be called., 7. In which access specifier should a virtual function be defined?, a) Private, b) Public, c) Protected, d) Default, View Answer
Page 199 :
Answer: b, Explanation: The virtual functions must be defined in public section of a class. This is to, ensure that the virtual function is available everywhere in the program. Also to avoid any, error while resolving the method., 8. Virtual functions can never be made _______________, a) Static function, b) Parameterized function, c) Default argument function, d) Zero parameter function, View Answer, Answer: a, Explanation: The virtual function must not be static. Those functions are the property of, individual objects and not of a class as a whole. The functions should not be made common, for all the objects of that class., 9. Virtual functions can’t be made friend function of other classes., a) True, b) False, View Answer, Answer: a, Explanation: The friend functions can access the private members also. This may hinder the, security of class members. This is why the functions should not be made friend functions of, other class., advertisement, , 10. Which is a must condition for virtual function to achieve runtime polymorphism?, a) Virtual function must be accessed with direct name, b) Virtual functions must be accessed using base class object, c) Virtual function must be accessed using pointer or reference, d) Virtual function must be accessed using derived class object only, View Answer, Answer: c, Explanation: The virtual functions must be called using pointer or reference. This is, mandatory so that the intended function gets executed while resolving the method at runtime., The must not be any ambiguity between the method of parent class and derived class., 11. Which among the following is true for virtual functions?, a) Prototype must be different in base and derived class, b) Prototype must be same in base class and derived class, c) Prototype must be given only in base class, d) Prototype must have different signature in base and derived class, View Answer, Answer: b, Explanation: The prototype must be the same. Because the function is to be overridden in the
Page 200 :
derived class. If the function prototype is different in derived class then it will not override, the base class function and hence virtual function concept won’t work here., 12. The virtual functions must be declared and defined in _____________ class and, overridden in ___________ class., a) Base, base, b) Derived, derived, c) Derived, base, d) Base, derived, View Answer, Answer: d, Explanation: The virtual functions must be declared and defined in base class. The functions, can be redefined in derived class. If redefined in derived class then it overrides the base class, function definition., 13. It is __________ to redefine the virtual function in derived class., a) Necessary, b) Not necessary, c) Not acceptable, d) Good practice, View Answer, Answer: b, Explanation: It is not necessary to redefine the virtual function in the derived class. If not, defined, the base class function definition is used but if defined, the intended definition is, used according to need. It is not about good coding practice as it should be redefined only if, needed., advertisement, , 14. Which among the following is true?, a) A class may have virtual destructor but not virtual constructor, b) A class may have virtual constructor but not virtual destructor, c) A class may have virtual constructor and virtual constructor, d) A class may have either virtual destructor or virtual constructor, View Answer, Answer: a, Explanation: Any class can contain virtual destructor. But is not possible to define a virtual, constructor. The reason behind is that the destructors can be overridden but constructors, should not be., 15. If virtual function of base class is redefined in derived class then ________________, a) It must be declared virtual in derived class also, b) It may or may not be declared virtual in derived class, c) It can must not be declared virtual in derived class, d) It must be declared normally in derived class, View Answer
Page 201 :
Answer: b, Explanation: The virtual functions may or may not be declared virtual in derived class. This, is because if the overriding function defined in derived class is not declared virtual explicitly,, the compiler makes it virtual implicitly., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Entrance exams, here is complete, set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Hybrid Inheritance, » Next - Object Oriented Programming Questions and Answers – Abstract Function, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Hybrid Inheritance, Object Oriented Programming Questions and Answers – Abstract Function, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on File Handling, 2. Python Programming Examples, 3. C# Programming Examples, 4. C# Programming Examples on Delegates, 5. C# Programming Examples on Arrays, 6. C# Programming Examples on Strings, 7. C# Programming Examples on Interfaces, 8. C Programming Examples on Strings, 9. Java Programming Examples, 10. Java Programming Examples on Multithreading, 11. Java Programming Examples on Java.Lang, 12. C# Basic Programming Examples, 13. Java Programming Examples on Exception Handling, 14. Java Programming Examples on Classes, 15. C Programming Examples on Mathematical Functions, 16. Java Programming Examples on Mathematical Functions, 17. Java Programming Examples on Inheritance, 18. C# Programming Examples on Inheritance, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers, advertisement
Page 202 :
Object Oriented Programming Questions, and Answers – Abstract Function, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on ― Abstract Function―., 1. Which among the following best defines the abstract methods?, a) Functions declared and defined in base class, b) Functions only declared in base class, c) Function which may or may not be defined in base class, d) Function which must be declared in derived class, View Answer, Answer: b, Explanation: The abstract functions must only be declared in base class. Their definitions are, provided by the derived classes. It is a mandatory condition., advertisement, , 2. Which among the following is true?, a) The abstract functions must be only declared in derived classes, b) The abstract functions must not be defined in derived classes, c) The abstract functions must be defined in base and derived class, d) The abstract functions must be defined either in base or derived class, View Answer, Answer: a, Explanation: The abstract functions can’t be defined in base class. They are to be defined, in derived classes. It is a rule for abstract functions., 3. How are abstract functions different from the abstract functions?, a) Abstract must not be defined in base class whereas virtual function can be defined, b) Either of those must be defined in base class, c) Different according to definition, d) Abstract functions are faster, View Answer, Answer: a, Explanation: The abstract functions are only declared in base class. Derived classes have to, implement those functions in order to inherit that base class. The functions are always, defined in derived classes only., 4. Which among the following is correct?, a) Abstract functions should not be defined in all the derived classes, b) Abstract functions should be defined only in one derived class, c) Abstract functions must be defined in base class
Page 203 :
d) Abstract functions must be defined in all the derived classes, View Answer, Answer: d, Explanation: The abstract function are only declared in base classes and then has to be, defined in all the derived classes. This allows all the derived classes to define own definition, of any function whose declaration in base class might be common to all the other derived, classes., 5. It is ____________________ to define the abstract functions., a) Mandatory for all the classes in program, b) Necessary for all the base classes, c) Necessary for all the derived classes, d) Not mandatory for all the derived classes, View Answer, Answer: c, Explanation: The derived classes must define the abstract function of base class in their own, body. This is a necessary condition. Because the abstract functions doesn’t contain any, definition in base class and hence becomes mandatory for the derived class to define them., All the functions in a program must have some definition., advertisement, , 6. The abstract function definitions in derived classes is enforced at _________, a) Runtime, b) Compile time, c) Writing code time, d) Interpreting time, View Answer, Answer: b, Explanation: When the program is compiled, these definitions are checked if properly, defined. This compiler also ensure that the function is being defined by all the derived, classes. Hence we get a compile time error if not done., 7. What is this feature of enforcing definitions of abstract function at compile time called?, a) Static polymorphism, b) Polymorphism, c) Dynamic polymorphism, d) Static or dynamic according to need, View Answer, Answer: c, Explanation: The feature is known as Dynamic polymorphism. Because the definitions are, resolved at runtime. Even though the definitions are checked at compile time, they are, resolved at runtime only., 8. What is the syntax for using abstract method?, a) <access-modifier>abstract<return-type>method_name (parameter), b) abs<return-type>method name (parameter)
Page 204 :
c) <access-modifier>abstract return-type method name (parameter), d) <access-modifier>abstract <returning> method name (parameter), View Answer, Answer: a, Explanation: The syntax must firstly contain the access modifier. Then the keyword abstract, is written to mention clearly to the compiler that it is an abstract method. Then prototype of, the function with return type, function name and parameters., 9. If a function declared as abstract in base class doesn’t have to be defined in derived, class then ______, a) Derived class must define the function anyhow, b) Derived class should be made abstract class, c) Derived class should not derive from that base class, d) Derived class should not use that function, View Answer, Answer: b, Explanation: If the function that is not to be defined in derived class but is declared as, abstract in base class then the derived class must be made an abstract class. This will make, the concept mandatory that the derived class must have one subclass to define that method., advertisement, , 10. Static methods can’t be made abstract in java., a) True, b) False, View Answer, Answer: a, Explanation: The abstract functions can’t be made static in a program. If those are made, static then the function will be a property of class rather than each object. In turn ever object, or derived class must use the common definition given in the base class. But abstract, functions can’t be defined in the base class. Hence not possible., 11. Which among the following is true?, a) Abstract methods can be static, b) Abstract methods can be defined in derived class, c) Abstract methods must not be static, d) Abstract methods can be made static in derived class, View Answer, Answer: c, Explanation: The abstract methods can never be made static. Even if it is in derived class, it, can’t be made static. If this happens, then all the subsequent sub classes will have a, common definition of abstract function which is not desirable., 12. Which among the following is correct for abstract methods?, a) It must have different prototype in the derived class, b) It must have same prototype in both base and derived class, c) It must have different signature in derived class
Page 205 :
d) It must have same return type only, View Answer, Answer: b, Explanation: The prototype must be the same. This is to override the function declared as, abstract in base class. Or else it will not be possible to override the abstract function of base, class and hence we get a compile time error., 13. If a class have all the abstract methods the class will be known as ___________, a) Abstract class, b) Anonymous class, c) Base class, d) Derived class, View Answer, Answer: a, Explanation: The classes containing all the abstract methods are known as abstract classes., And the abstract classes can never have any normal function with definition. Hence known as, abstract class., advertisement, , 14. The abstract methods can never be ___________ in a base class., a) Private, b) Protected, c) Public, d) Default, View Answer, Answer: a, Explanation: The base class must not contain the abstract methods. The methods have to be, derived and defined in derived class. But if it is made private it can’t be inherited. Hence, we can’t declare it as a private member., 15. The abstract method definition can be made ___________ in derived class., a) Private, b) Protected, c) Public, d) Private, public, or protected, View Answer, Answer: d, Explanation: The derived class implements the definition of the abstract methods of base, class. Those can be made private in derived class if security is needed. There won’t be, any problem in declaring it as private., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers.
Page 206 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Virtual Functions, » Next - Object Oriented Programming Questions and Answers – Types of Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Virtual Functions, Object Oriented Programming Questions and Answers – Types of Member Functions, advertisement, advertisement, , Recommended Posts:, 1. C# Questions and Answers, 2. C# Programming Examples on Interfaces, 3. Java Programming Examples on Event Handling, 4. Java Programming Examples on Mathematical Functions, 5. Java Programming Examples on Networking, 6. Java Programming Examples on File Handling, 7. C++ Questions and Answers, 8. C# Programming Examples, 9. Java Programming Examples on Utility Classes, 10. C# Basic Programming Examples, 11. Java Programming Examples on Exception Handling, 12. Ruby Programming Questions and Answers, 13. Java Programming Examples on Multithreading, 14. Java Programming Examples on Java.Lang, 15. Java Programming Examples, 16. C# Programming Examples on Inheritance, 17. C# Programming Examples on Functions, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Types of Member, Functions, « Prev, Next », , This set of Object Oriented Programming Problems focuses on “Types of Member, Functions―.
Page 207 :
1. How many types of member functions are possible in general?, a) 2, b) 3, c) 4, d) 5, View Answer, Answer: d, Explanation: There are basically 5 types of member functions possible. The types include, simple, static, const, inline, and friend member functions. Any of these types can be used in a, program as per requirements., advertisement, , 2. Simple member functions are ______________________, a) Ones defined simply without any type, b) Ones defined with keyword simple, c) Ones that are implicitly provided, d) Ones which are defined in all the classes, View Answer, Answer: a, Explanation: When there is no type defined for any function and just a simple syntax is used, with the return type, function name and parameter list then those are known as simple, member functions. This is a general definition of simple members., 3. What are static member functions?, a) Functions which use only static data member but can’t be accessed directly, b) Functions which uses static and other data members, c) Functions which can be accessed outside the class with the data members, d) Functions using only static data and can be accessed directly in main() function, View Answer, Answer: d, Explanation: The static member functions can be accessed directly in the main function., There is no restriction on direct use. We can call them with use of objects also. But the, restriction is that the static member functions can only use the static data members of the, class., 4. How can static member function can be accessed directly in main() function?, a) Dot operator, b) Colon, c) Scope resolution operator, d) Arrow operator, View Answer, Answer: c, Explanation: The static member functions can be accessed directly in the main() function., The only restriction is that those must use only static data members of the class. These, functions are property of class rather than each object.
Page 208 :
5. Correct syntax to access the static member functions from the main() function is, ______________, a) classObject::functionName();, b) className::functionName();, c) className:classObject:functionName();, d) className.classObject:functionName();, View Answer, Answer: b, Explanation: The syntax in option b must be followed in order to call the static functions, directly from the main() function. That is a predefined syntax. Scope resolution helps to spot, the correct function in the correct class., advertisement, , 6. What are const member functions?, a) Functions in which none of the data members can be changed in a program, b) Functions in which only static members can be changed, c) Functions which treat all the data members as constant and doesn’t allow changes, d) Functions which can change only the static members, View Answer, Answer: c, Explanation: The const member functions are intended to keep the value of all the data, members of a class same and doesn’t allow any changes on them. The data members are, treated as constant data and any modification inside the const function is restricted., 7. Which among the following best describes the inline member functions?, a) Functions defined inside the class only, b) Functions with keyword inline only, c) Functions defined outside the class, d) Functions defined inside the class or with the keyword inline, View Answer, Answer: d, Explanation: The functions which are defined with the keyword inline or are defined inside, the class are treated to be inline functions. Definitions inside the class are implicitly made, inline if none of the complex statements are used in the definition., 8. What are friend member functions (C++)?, a) Member function which can access all the members of a class, b) Member function which can modify any data of a class, c) Member function which doesn’t have access to private members, d) Non-member functions which have access to all the members (including private) of a class, View Answer, Answer: d, Explanation: A non-member function of a class which can access even the private data of a, class is a friend function. It is an exception on access to private members outside the class. It, is sometimes considered as a member functions since it has all the access that a member, function in general have.
Page 209 :
9. What is the syntax of a const member function?, a) void fun() const {}, b) void fun() constant {}, c) void const fun() {}, d) const void fun(){}, View Answer, Answer: a, Explanation: The general syntax to be followed in order to declare a const function in a class, is as in option a. The syntax may vary in different programming languages., advertisement, , 10. Which keyword is used to make a nonmember function as friend function of a class?, a) friendly, b) new, c) friend, d) connect, View Answer, Answer: c, Explanation: The keyword friend is provided in programming languages to use it whenever a, functions is to be made friend of one class or other. The keyword indicates that the function is, capable of new functionalities like accessing private members., 11. Member functions _____________________, a) Must be defined inside class body, b) Can be defined inside class body or outside, c) Must be defined outside the class body, d) Can be defined in another class, View Answer, Answer: c, Explanation: The functions definitions can be given inside or outside the body of class. If, defined inside, general syntax is used. If defined outside then the class name followed by, scope resolution operator and then function name must be given for the definition., 12. All type of member functions can’t be used inside a single class., a) True, b) False, View Answer, Answer: b, Explanation: There is no restriction on the use of type of member functions inside a single, class. Any type any number of times can be defined inside a class. The member functions can, be used as required., 13. Which among the following is true?, a) Member functions can never be private, b) Member functions can never be protected, c) Member functions can never be public
Page 210 :
d) Member functions can be defined in any access specifier, View Answer, Answer: d, Explanation: The member functions can be defined inside any specifier. There is no, restriction. The programmer can apply restrictions on its use by specifying the access, specifier with the functions., advertisement, , 14. Which keyword is used to define the static member functions?, a) static, b) stop, c) open, d) state, View Answer, Answer: a, Explanation: The static keyword is used to declare any static member function in a class. The, static members become common to each object of the class being created. They share the, same values., 15. Which keyword is used to define the inline member function?, a) no keyword required, b) inline, c) inlined, d) line, View Answer, Answer: b, Explanation: The inline keyword is used to defined the inline member functions in a class., The functions are implicitly made inline if defined inside the class body, but only if they, doesn’t have any complex statement inside. All functions defined outside the class body, must be mentioned with explicit inline keyword., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming Problems, here is complete set of, 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Abstract Function, » Next - Object Oriented Programming Questions and Answers – Member Operator, Function, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Abstract Function
Page 211 :
Object Oriented Programming Questions and Answers – Member Operator Function, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples on Strings, 2. R Programming Questions and Answers, 3. C++ Questions and Answers, 4. C Programming Examples on Linked List, 5. C Questions and Answers, 6. C# Programming Examples on Files, 7. Java Programming Examples on Exception Handling, 8. Java Programming Examples, 9. Java Programming Examples on String Handling, 10. Ruby Programming Questions and Answers, 11. Java Programming Examples on Collections, 12. Java Programming Examples on Multithreading, 13. Java Programming Examples on Java.Lang, 14. Java Programming Examples on File Handling, 15. C Programming Examples on Mathematical Functions, 16. Java Programming Examples on Mathematical Functions, 17. C# Programming Examples on Functions, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Member Operator, Function, « Prev, Next », , This set of Object Oriented Programming Questions and Answers for Aptitude test focuses, on “Member Operator Function―., 1. Which among the following are valid ways of overloading the operators?, a) Only using friend function, b) Only using member function, c) Either member functions or friend functions can be used, d) Operators can’t be overloaded, View Answer, Answer: c, Explanation: The operators can be overloaded by using the member function or even the
Page 212 :
friend functions can be used. This is because both of these can access all the data members of, a class., advertisement, , 2. Which among the following is mandatory condition for operators overloading?, a) Overloaded operator must be member function of the left operand, b) Overloaded operator must be member function of the right operand, c) Overloaded operator must be member function of either left or right operand, d) Overloaded operator must not be dependent on the operands, View Answer, Answer: a, Explanation: The operator to be overloaded must be made the member function of the, operand on left side of expressions to be used. This allows the compiler to identify whether, the overloading has to be used or not. This rule also reduces the ambiguity in code., 3. When the operator to be overloaded becomes the left operand member then, ______________, a) The right operand acts as implicit object represented by *this, b) The left operand acts as implicit object represented by *this, c) Either right or left operand acts as implicit object represented by *this, d) *this pointer is not applicable in that member function, View Answer, Answer: b, Explanation: The left operand becomes the object that is referred by *this pointer in the, member function that will be called while using operator overloading. This is done to point to, a specific object on which the overloading will be applied., 4. If the left operand is pointed by *this pointer, what happens to other operands?, a) Other operands are passed as function return type, b) Other operands are passed to compiler implicitly, c) Other operands must be passed using another member function, d) Other operands are passed as function arguments, View Answer, Answer: d, Explanation: The operands that are used during overloading expect the left operand, can be, passed as function arguments. Those are then referred in function definition with the names, specified in the argument list., 5. If a friend overloaded operator have to be changed to member overloaded operator, which, operator should be used with the class name?, a) Scope resolution operator, b) Colon, c) Arrow operator, d) Dot operator, View Answer
Page 213 :
Answer: a, Explanation: The scope resolution operator can be used followed by the class name. Then the, operator keyword with the operator symbol that should be overloaded. This is done to use, member function instead of friend function., advertisement, , 6. What is the syntax to overload an operator?, a) className::operator<operatorSymbol>(parameters), b) className:operator<operatorSymbol>(parameters), c) className.operator<operatorSymbol>(paramteres), d) className->operator<operatorSymbol>(parameters), View Answer, Answer: a, Explanation: The class name is followed by the scope resolution operator. This is done to, specify the class to which the function should belong to. Then the keyword operator should, be used in order to indicate the operator that is to be overloaded. Then come the parameters, list to specify other operands., 7. Why the left parameter is removed from parameter list?, a) Because it is of no use, b) Because it is never used in definitions, c) Because it becomes parameter pointed by *this, d) Because it can’t be referred by *this pointer, View Answer, Answer: c, Explanation: The left object is removed from being passed as a parameter, because it is, implicitly passed. It is passed implicitly because it is considered the object with respect to, which the overloading function is being called., 8. Which object’s members can be called directly while overloading operator function is, used (In function definition)?, a) Left operand members, b) Right operand members, c) All operand members, d) None of the members, View Answer, Answer: a, Explanation: This is because the left operand is passed implicitly. It is pointed by *this. This, in turn means we can use the direct member names of the object because those are again, converted to a syntax containing *this pointer implicitly., 9. If left operand member is specified directly in the function definition, which is the correct, implicit conversion of that syntax?, a) *this className, b) *this parameterObject, c) *this returnedObject
Page 214 :
d) *this object, View Answer, Answer: d, Explanation: Since the left operands are passed implicitly, those object members can be, accessed directly in the function definition. The compiler converts the syntax into the syntax, that can be processed. The implicitly converted syntax contains *this pointer followed by the, objectName that is left operand in the expression., advertisement, , 10. When the friend operator overloading is converted into member operator overloading, _______________, a) Two parameters of friend function remains same parameters in member operator, overloading, b) Two parameters of friend function becomes only one parameter of member function, c) Two parameters of friend function are removed while using member function, d) Two parameters of friend function are made 4 in member operator overloading, View Answer, Answer: b, Explanation: The friend function would accept two arguments if some binary operator is, overloaded. When we try to convert that definition to member operator overloading then it, becomes only one parameter. The reason behind is that the left operand is passed implicitly, while using the member functions., 11. Where in the parameter list is the implicit *this is added?, a) Right most parameter, b) Anywhere in parameter list, c) Left most parameter, d) Not added to parameter list, View Answer, Answer: c, Explanation: The left operand is passed implicitly by the compiler to the member function., But this is done, when the compiler adds the calling object as *this to the parameter list. It is, always added as the left most parameter, i.e. the first parameter of the function., 12. Which operator among the following can be overloading using only member function?, a) Assignment operator, b) Addition operator, c) Subtraction operator, d) Multiplication and division operator, View Answer, Answer: a, Explanation: Only the assignment operator among the options given must be overloaded, using the member functions. The assignment operator can’t be overloaded using friend, function. This is a restriction in the programming languages to make the programs more, resistant towards errors.
Page 215 :
13. Which operator among the following can be overloaded using both friend function and, member function?, a) Assignment operator, b) Subscript, c) Member selection (arrow operator), d) Modulus operator, View Answer, Answer: d, Explanation: Only the modulus operator among the given operators can be overloaded using, either friend function or member function. Other operators must be overloaded using only the, member functions., advertisement, , 14. All the operators can be overloaded using the member function operator overloading., a) True, b) False, View Answer, Answer: b, Explanation: It is not the case that all the operators can be overloaded using the member, operator overloading. There are some cases where the operators must be overloaded using the, friend function only. The reason behind is that the left operand should be passed *this, pointer, but the left operand in these cases might be object of some other class. Hence, can’t be done., 15. Which operator among the following must be overloaded using the friend function?, a) << operator only, b) >> operator only, c) Both << and >> operators, d) It’s not mandatory to use friend function in any case, View Answer, Answer: c, Explanation: In some cases it is mandatory to use the friend functions for overloading the, operators. Here both the << and >> operators must be overloaded using friend function, because the left operand is object of some other class and the right operand is usually of some, different type., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Aptitude test, here is complete set, of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Page 216 :
« Prev - Object Oriented Programming Questions and Answers – Types of Member, Functions, » Next - Object Oriented Programming Questions and Answers – Overloading Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Types of Member Functions, Object Oriented Programming Questions and Answers – Overloading Member Functions, advertisement, advertisement, , Recommended Posts:, 1. Simple Java Programs, 2. Java Programming Examples on Exception Handling, 3. Python Questions and Answers, 4. C# Programming Examples on Arrays, 5. Java Programming Examples, 6. C# Questions and Answers, 7. Java Programming Examples on Multithreading, 8. Java Programming Examples on Mathematical Functions, 9. C Tutorials, 10. Java Programming Examples on Networking, 11. Java Programming Examples on Java.Lang, 12. C# Programming Examples on Conversions, 13. Java Programming Examples on Inheritance, 14. C# Basic Programming Examples, 15. C Programming Examples on Bitwise Operations, 16. Java Programming Examples on Classes, 17. C++ Questions and Answers, 18. C# Programming Examples on Functions, 19. Ruby Programming Questions and Answers, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Overloading Member, Functions, « Prev, Next », , This set of Object Oriented Programming Questions and Answers for Freshers focuses on, “Overloading Member Functions―., 1. What does memory allocation for objects mean?, a) Actual creation and memory allocation for object members, b) Creation of member functions
Page 217 :
c) Creation of data members for a class, d) Actual creation and data declaration for object members, View Answer, Answer: a, Explanation: The memory allocated for the object members indicates actual creation of the, object members. This is known as memory allocation for object., advertisement, , 2. Where is the memory allocated for the objects?, a) HDD, b) Cache, c) RAM, d) ROM, View Answer, Answer: c, Explanation: The memory for the objects or any other data is allocated in RAM initially. This, is while we run a program all the memory allocation takes place in some RAM segments., Arrays in heap and local members in stack etc., 3. When is the memory allocated for an object?, a) At declaration of object, b) At compile time, c) When object constructor is called, d) When object is initialized to another object, View Answer, Answer: c, Explanation: The object memory allocation takes place when the object constructor is called., Declaration of an object doesn’t mean that memory is allocated for its members. If object, is initialized with another object, it may just get a reference to the previously created object., 4. Using new is type safe as _______________________, a) It require to be specified with type of data, b) It doesn’t require to be specified with type of data, c) It requires the name of data, d) It allocated memory for the data, View Answer, Answer: b, Explanation: The new is type safe because we don’t have to specify the type of data that, have to be allocated with memory. We can directly use it with data name. Name of the data, doesn’t matter though for type of memory allocation though., 5. Which of the following function can be used for dynamic memory allocation of objects?, a) malloc(), b) calloc(), c) create()
Page 218 :
d) both malloc() and calloc(), View Answer, Answer: d, Explanation: The malloc() function can be used to allocate dynamic memory for objects., Function calloc() can also be use. These functions differ in the way they allocate memory for, objects., advertisement, , 6. How much memory will be allocated for an object of class given below?, class Test{, int mark1;, int mark2;, float avg;, char name[10];, };, , a) 22 Bytes, b) 24 Bytes, c) 20 Bytes, d) 18 Bytes, View Answer, Answer: a, Explanation: The size of an object of the class given in question will be of size 22 bytes. This, is because the size of an object is always equal to the sum of sizes of the data members of the, class, except static members., 7. Which keyword among the following can be used to declare an array of objects in java?, a) new, b) create, c) allocate, d) arr, View Answer, Answer: a, Explanation: The keyword new can be used to declare an array of objects in java. The syntax, must be specified with an object pointer which is assigned with a memory space containing, the required number of object space. Even initialization can be done directly., 8. When is the memory allocated for an object gets free?, a) At termination of program, b) When object goes out of scope, c) When main function ends, d) When system restarts, View Answer, Answer: b, Explanation: Whenever an object goes out of scope, the deletion of allocation memory takes, place. Actually the data is not deleted, instead the memory space is flagged to be free for
Page 219 :
further use. Hence whenever an object goes out of scope the object members become useless, and hence memory is set free., advertisement, , 9. Which among the following keyword can be used to free the allocated memory for an, object?, a) delete, b) free, c) either delete or free, d) only delete, View Answer, Answer: c, Explanation: The memory allocated for an object is usually automatically made free. But if, explicitly memory has to be made free then we can use either free or delete keywords, depending on programming languages., 10. Which function is called whenever an object goes out of scope?, a) Destructor function, b) Constructor function, c) Delete function, d) Free function, View Answer, Answer: a, Explanation: The destructor function of the class is called whenever an object goes out of, scope. This is because the destructor set all the resources, acquired by the object, free. This is, an implicit work of compiler., 11. Which operator can be used to check the size of an object?, a) sizeof(objectName), b) size(objectName), c) sizeofobject(objectName), d) sizedobject(objectName), View Answer, Answer: a, Explanation: The sizeof operator is used to get the size of an already created object. This, operator must constail keyword sizeof(objectName). The output will give the number of, bytes acquired by a single object of some class., 12. The memory allocated for an object ____________________, a) Can be only dynamic, b) Can be only static, c) Can be static or dynamic, d) Can’t be done using dynamic functions, View Answer, Answer: c, Explanation: The memory allocation for an object can be static or dynamic. The static
Page 220 :
memory allocation is when an object is declared directly without using any function usually., And dynamic allocation is when we use some dynamic allocation function to allocate, memory for data member of an object., 13. If an object is declared in a user defined function __________________, a) Its memory is allocated in stack, b) Its memory is allocated in heap, c) Its memory is allocated in HDD, d) Its memory is allocated in cache, View Answer, Answer: a, Explanation: The memory for any data or object that are used in a user defined function are, always allocated in the stack. This is to ensure that the object is destroyed as soon as the, function is returned. Also this ensures that the correct memory allocation and destruction is, performed., advertisement, , 14. In java ______________ takes care of managing memory for objects dynamically., a) Free collector, b) Dust collector, c) Memory manager, d) Garbage collector, View Answer, Answer: d, Explanation: The garbage collector in java takes care of the memory allocations and their, deletions dynamically. When an object is no more required then the garbage collector deletes, the object and free up all the resources that were held by that object., 15. Which operator can be used to free the memory allocated for an object in C++?, a) Free(), b) delete, c) Unallocate, d) Collect, View Answer, Answer: b, Explanation: The delete operator in C++ can be used to free the memory and resources held, by an object. The function can be called explicitly whenever required. In C++ memory, management must be done by the programmer. There is no automatic memory management, in C++., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Freshers, here is complete set of, 1000+ Multiple Choice Questions and Answers.
Page 221 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Member Operator, Function, » Next - Object Oriented Programming Questions and Answers – Overriding Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Member Operator Function, Object Oriented Programming Questions and Answers – Overriding Member Functions, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Utility Classes, 2. C++ Programming Examples on Computational Geometry Problems & Algorithms, 3. Python Programming Examples on Stacks & Queues, 4. C Programming Examples on Computational Geometry Problems & Algorithms, 5. Java Programming Examples on String Handling, 6. C# Programming Examples on Files, 7. Java Programming Examples on Data-Structures, 8. Java Programming Examples, 9. Java Programming Examples on Inheritance, 10. Ruby Programming Questions and Answers, 11. Java Programming Examples on Collections, 12. C Programming Examples on Linked List, 13. Java Programming Examples on Mathematical Functions, 14. C Programming Examples on Mathematical Functions, 15. Java Programming Examples on Classes, 16. Java Programming Examples on File Handling, 17. Java Programming Examples on Java.Lang, 18. C# Programming Examples on Functions, 19. C Programming Examples on Stacks & Queues, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Overriding Member, Functions, « Prev, Next »
Page 222 :
This set of Object Oriented Programming Interview Questions and Answers for freshers, focuses on “Overriding Member Functions―., 1. Which among the following best describes member function overriding?, a) Member functions having same name in base and derived classes, b) Member functions having same name in base class only, c) Member functions having same name in derived class only, d) Member functions having same name and different signature inside main function, View Answer, Answer: a, Explanation: The member function which is defined in base class and again in the derived, class, is overridden by the definition given in the derived class. This is because the preference, is given more to the local members. When derived class object calls that function, definition, from the derived class is used., advertisement, , 2. Which among the following is true?, a) Inheritance must not be using when overriding is used, b) Overriding can be implemented without using inheritance, c) Inheritance must be done, to use overriding are overridden, d) Inheritance is mandatory only if more than one functions, View Answer, Answer: c, Explanation: The inheritance must be used in order to use function overriding. If inheritance, is not used, the functions can only be overloaded. There must be a base class and a derived, class to override the function of base class., 3. Which is the correct condition for function overriding?, a) The declaration must not be same in base and derived class, b) The declaration must be exactly the same in base and derived class, c) The declaration should have at least 1 same argument in declaration of base and derived, class, d) The declaration should have at least 1 different argument in declaration of base and, derived class, View Answer, Answer: b, Explanation: For a function to be over ridden, the declaration must be exactly the same., There must not be any different syntax used. This will ensure that the function to be, overridden is only the one intended from to be overridden from the derived class., 4. Exactly same declaration in base and derived class includes______________, a) Only same name, b) Only same return type and name, c) Only same return type and argument list, d) All the same return type, name and parameter list, View Answer
Page 223 :
Answer: d, Explanation: Declaration includes the whole prototype of the function. The return type name, and the parameter list must be same in order to confirm that the function is same in derived, and the base class. And hence can be overridden., 5. Which among function will be overridden from the function defined in derived class, below:, advertisement, , class A, {, int i;, void show(), {, cout<<i;, }, void print(), {, cout <<i;, }, };, class B, {, int j;, void show(), {, cout<<j;, }, };, , a) show(), b) print(), c) show() and print(), d) Compile time error, View Answer, Answer: a, Explanation: The declaration must be exactly same in the derived class and base class. The, derived class have defined show() function with exactly same declaration. This then shows, that the function in base class is being overridden if show() is called from the object of class, B., 6. How to access the overridden method of base class from the derived class?, a) Using arrow operator, b) Using dot operator, c) Using scope resolution operator, d) Can’t be accessed once overridden, View Answer, Answer: c, Explanation: Scope resolution operator :: can be used to access the base class method even if, overridden. To access those, first base class name should be written followed by the scope, resolution operator and then the method name.
Page 224 :
7. The functions to be overridden _____________, a) Must be private in base class, b) Must not be private base class, c) Must be private in both derived and base class, d) Must not be private in both derived and base class, View Answer, Answer: b, Explanation: If the function is private in the base class, derived class won’t be able to, access it. When the derived class can’t access the function to be overridden then it, won’t be able to override it with any definition., 8. Which language doesn’t support the method overriding implicitly?, a) C++, b) C#, c) Java, d) SmallTalk, View Answer, Answer: b, Explanation: The feature of method overriding is not provided in C#. To override the, methods, one must use override or virtual keywords explicitly. This is done to remove, accidental changes in program and unintentional overriding., advertisement, , 9. In C# ____________________, a) Non – virtual or static methods can’t be overridden, b) Non – virtual and static methods only can be overridden, c) Overriding is not allowed, d) Overriding must be implemented using C++ code only, View Answer, Answer: a, Explanation: The non-virtual and static methods can’t be overridden in C# language. The, restriction is made from the language implicitly. Only the methods that are abstract, virtual or, override can be overridden., 10. In Delphi ______________, a) Method overriding is done implicitly, b) Method overriding is not supported, c) Method overriding is done with directive override, d) Method overriding is done with the directive virtually, View Answer, Answer: c, Explanation: This is possible but only if the method to be overridden is marked as dynamic or, virtual. It is inbuilt restriction of programming language. This is done to reduce the accidental, or unintentional overriding.
Page 225 :
11. What should be used to call the base class method from the derived class if function, overriding is used in Java?, a) Keyword super, b) Scope resolution, c) Dot operator, d) Function name in parenthesis, View Answer, Answer: a, Explanation: The keyword super must be used to access base class members. Even when, overriding is used, super must be used with the dot operator. The overriding is possible., 12. In Kotlin, the function to be overridden must be ______________, a) Private, b) Open, c) Closed, d) Abstract, View Answer, Answer: b, Explanation: The function to be overridden must be open. This is a condition in Kotlin for, any function to be overridden. This avoids accidental overriding., 13. Abstract functions of a base class _________________, a) Are overridden by the definition in same class, b) Are overridden by the definition in parent class, c) Are not overridden generally, d) Are overridden by the definition in derived class, View Answer, Answer: d, Explanation: The functions declared to be abstract in base class are redefined in derived, classes. That is, the functions are overridden by the definitions given in the derived classes., This must be done to give at least one definition to each undefined function., advertisement, , 14. If virtual functions are defined in the base class then _______________, a) It is not necessary for derived classes to override those functions, b) It is necessary for derived classes to override those functions, c) Those functions can never be derived, d) Those functions must be overridden by all the derived classes, View Answer, Answer: a, Explanation: The derived classes doesn’t have to redefine and override the base class, functions. If one definition is already given it is not mandatory for any derived class to, override those functions. The base class definition will be used., 15. Which feature of OOP is exhibited by the function overriding?, a) Inheritance
Page 226 :
b) Abstraction, c) Polymorphism, d) Encapsulation, View Answer, Answer: c, Explanation: The polymorphism feature is exhibited by function overriding. Polymorphism is, the feature which basically defines that same named functions can have more than one, functionalities., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Interviews, here is complete set of, 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Overloading Member, Functions, » Next - Object Oriented Programming Questions and Answers – Constant Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Overloading Member Functions, Object Oriented Programming Questions and Answers – Constant Member Functions, advertisement, advertisement, , Recommended Posts:, 1. C++ Programming Examples on STL, 2. Python Programming Examples, 3. Java Programming Examples on Collections, 4. Java Programming Examples on Utility Classes, 5. Java Programming Examples on Event Handling, 6. Java Programming Examples on Networking, 7. C++ Questions and Answers, 8. C# Programming Examples, 9. Java Programming Examples on Multithreading, 10. Java Programming Examples, 11. Ruby Programming Questions and Answers, 12. C# Basic Programming Examples, 13. Java Programming Examples on Classes, 14. C Programming Examples on Mathematical Functions, 15. Java Programming Examples on Java.Lang, 16. Java Programming Examples on Mathematical Functions, 17. C# Programming Examples on Inheritance
Page 227 :
18. C# Programming Examples on Functions, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Constant Member, Functions, « Prev, Next », , This set of Object Oriented Programming Quiz focuses on “Constant Member, Functions―., 1. What are the constant member functions?, a) Functions which doesn’t change value of calling object, b) Functions which doesn’t change value of any object inside definition, c) Functions which doesn’t allow modification of any object of class, d) Functions which doesn’t allow modification of argument objects, View Answer, Answer: a, Explanation: The constant member functions are a special type of member functions. These, are intended to restrict any modification in to the values of object which is used to invoke that, function. This is done to ensure that there are no accidental modifications to the object., advertisement, , 2. Which keyword must be used to declare a member function as a constant member, function?, a) Constant, b) Const, c) FunctionConst, d) Unchanged, View Answer, Answer: b, Explanation: The keyword const is provided in most of the programming languages. This, indicates that the member on which it is specified remains constant with the respective values, of members. The keyword must be mentioned so as to declare a member function to be, constant., 3. Which objects can call the const functions?, a) Only const objects, b) Only non-const objects, c) Both const and non-const objects
Page 228 :
d) Neither const not non-const objects, View Answer, Answer: c, Explanation: All the objects of a class can call const functions for its use. Const objects can, call the const functions to since those values are already constant. And the non- const objects, can call the const functions to keep their values constant., 4. Non-const functions _______________________, a) Can be called only from non-const object, b) Can be called only from const object, c) Can be called both by const and non-const object, d) Can’t be called with object, View Answer, Answer: a, Explanation: The non-const functions are able to modify the values of object which called the, function. So only the non-const functions can be called. If const object is used then the, compiler produces an error as the const object is being given to a function which can modify, its values., 5. Which is the correct condition on const member functions?, a) Const member functions can’t call non-const member functions, b) Const member functions can’t call any other function, c) Const member functions can call only the functions which are neither const nor non-const, d) Const member functions can call only data members of call not member functions, View Answer, Answer: a, Explanation: The const member functions are restricted to call any other non-const member, functions. This is to ensure that the const function doesn’t have any code that might, modify the calling object., advertisement, , 6. If a const object calls a non-const member function then ____________________, a) Run time error may get produced, b) Compile time error may get produced, c) Either compile time or run time error is produced, d) The program can’t be compiled, View Answer, Answer: b, Explanation: The program gets compiled but produces an error. The error is produced, because a constant value is being changed. Even if there is no code that can change any, object value, but non-const member functions are assumed to change the values., 7. Can a constructor function be constant?, a) Yes, always, b) Yes, only if permissions are given, c) No, because objects are not involved
Page 229 :
d) No, never, View Answer, Answer: d, Explanation: The constructors can’t be made const. This is to ensure that the constructor, is capable of initializing the values to the members of the object. If it is made constant then it, won’t be able to initialize any data member values., 8. A function can have both the const and non-const version in the same program., a) True, b) False, View Answer, Answer: a, Explanation: The functions in a program can be made both const and non-const. This feature, is made available to make programming more flexible. This ensures the security too as we, can call const function whenever required., 9. How is it possible to have both const and non-const version of a function?, a) Function overriding, b) Function prototyping, c) Function overloading, d) Function declaring, View Answer, Answer: c, Explanation: The functions can be declared const and non-const in the same program. The, technique used is function overloading. We can define a const function and then a non-const, version of same function using overloading., advertisement, , 10. When both the const and non-const version of functions are required?, a) Return value have to be different in const, b) Return value have to be same in const, c) Return values have to be ignored, d) Return values have to be suppressed, View Answer, Answer: a, Explanation: The return values can help to overload the functions. Also, this will allow us to, use a non-const function to be called inside both the const and non-const version of functions., 11. If a function is to be made const, which is the correct syntax?, a) const functionName(parameters);, b) const returnType functionName(parameters);, c) const functionName(returnType)(Parameters);, d) const (functionName(parameters));, View Answer
Page 230 :
Answer: b, Explanation: The function declaration must contain the keyword const. The const keyword, makes the function const type. The usual function declaration can be given followed by the, keyword. The keyword const can be given after the declaration of function and before, definition., 12. Functions which differ in const-ness are considered ______________________, a) To have same signature, b) To have different signature, c) To produce compile time error, d) To produce runtime error, View Answer, Answer: b, Explanation: The functions are considered to have different signature. This is because the, const-ness also defines the type of function or the working of functions. And hence the, functions can be considered different. This is the reason that we can use function overloading, for const and non-const version of same function., 13. If const version of a function when overloading is used, the function, ___________________, a) Returns reference to object, b) Returns volatile reference, c) Returns mutable reference, d) Returns const reference, View Answer, Answer: d, Explanation: The function returns a const reference. This is to ensure that the value of object, calling the function is not modified. This is a security feature., advertisement, , 14. Which among the following is recommended for const functions?, a) Const function use should be reduced in a program, b) Const function use should be more in a program, c) Const function use should not matter in a program, d) Const function use should be able to modify the values, View Answer, Answer: b, Explanation: The const member functions should be used more in a program. The reason, behind is to ensure there is no accidental modification of data of object. Also to ensure any, unintended modification which may result in unexpected termination of program., 15. Use of const member function in a program _________________________, a) Is mandatory, always, b) Is optional, always, c) Is mandatory, if objects are used, d) Is optional, if const objects are used, View Answer
Page 231 :
Answer: b, Explanation: The use of const member functions is not mandatory. If const objects are, involved then there is a high use of const member functions too. But there is no mandatory, condition., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Quizzes, here is complete set of, 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Overriding Member, Functions, » Next - Object Oriented Programming Questions and Answers – Private Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Overriding Member Functions, Object Oriented Programming Questions and Answers – Private Member Functions, advertisement, advertisement, , Recommended Posts:, 1. C++ Programming Examples on STL, 2. C# Programming Examples on Interfaces, 3. C# Programming Examples on Matrix, 4. C Programming Examples on Stacks & Queues, 5. C# Programming Examples on LINQ, 6. Java Programming Examples on Collections, 7. Java Programming Examples on Exception Handling, 8. C Programming Examples on Strings, 9. C# Programming Examples on Delegates, 10. Java Programming Examples on File Handling, 11. Java Programming Examples on Multithreading, 12. Ruby Programming Questions and Answers, 13. C# Programming Examples on Arrays, 14. Java Programming Examples on Java.Lang, 15. Java Programming Examples on Inheritance, 16. Java Programming Examples on Mathematical Functions, 17. Java Programming Examples on Classes, 18. C Programming Examples on Mathematical Functions, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers, advertisement
Page 232 :
Object Oriented Programming Questions, and Answers – Private Member, Functions, « Prev, Next », , This set of Object Oriented Programming Multiple Choice Questions & Answers focuses on, “Private Member Functions―., 1. Which is private member functions access scope?, a) Member functions which can only be used within the class, b) Member functions which can used outside the class, c) Member functions which are accessible in derived class, d) Member functions which can’t be accessed inside the class, View Answer, Answer: a, Explanation: The member functions can be accessed inside the class only if they are private., The access is scope is limited to ensure the security of the private members and their usage., advertisement, , 2. Which among the following is true?, a) The private members can’t be accessed by public members of the class, b) The private members can be accessed by public members of the class, c) The private members can be accessed only by the private members of the class, d) The private members can’t be accessed by the protected members of the class, View Answer, Answer: b, Explanation: The private members are accessible within the class. There is no restriction on, use of private members by public or protected members. All the members can access the, private member functions of the class., 3. Which member can never be accessed by inherited classes?, a) Private member function, b) Public member function, c) Protected member function, d) All can be accessed, View Answer, Answer: a, Explanation: The private member functions can never be accessed in the derived classes. The, access specifiers is of maximum security that allows only the members of self class to access, the private member functions.
Page 233 :
4. Which syntax among the following shows that a member is private in a class?, a) private: functionName(parameters), b) private(functionName(parameters)), c) private functionName(parameters), d) private::functionName(parameters), View Answer, Answer: c, Explanation: The function declaration must contain private keyword follower by the return, type and function name. Private keyword is followed by normal function declaration., 5. If private member functions are to be declared in C++ then _____________, a) private: <all private members>, b) private <member name>, c) private(private member list), d) private :- <private members>, View Answer, Answer: a, Explanation: The private members doesn’t have to have the keyword with each private, member. We only have to specify the keyword private followed by single colon and then, private member’s are listed., advertisement, , 6. In java, which rule must be followed?, a) Keyword private preceding list of private member’s, b) Keyword private with a colon before list of private member’s, c) Keyword private with arrow before each private member, d) Keyword private preceding each private member, View Answer, Answer: d, Explanation: The private keyword must be mentioned before each private member. Unlike, the rule in C++ to specify private once and list all other private member’s, in java all, member declarations must be preceded by the keyword private., 7. How many private member functions are allowed in a class?, a) Only 1, b) Only 7, c) Only 255, d) As many as required, View Answer, Answer: d, Explanation: There are no conditions applied on the number of private member functions that, can be declared in a class. Though the system may restrict use of too many functions, depending on memory., 8. How to access a private member function of a class?, a) Using object of class
Page 234 :
b) Using object pointer, c) Using address of member function, d) Using class address, View Answer, Answer: c, Explanation: Even the private member functions can be called outside the class. This is, possible if address of the function is known. We can use the address to call the function, outside the class., 9. Private member functions ____________, a) Can’t be called from enclosing class, b) Can be accessed from enclosing class, c) Can be accessed only if nested class is private, d) Can be accessed only if nested class is public, View Answer, Answer: a, Explanation: The nested class members can’t be accessed in the enclosed class even, though other members can be accessed. This is to ensure the class members security and not, to go against the rules of private members., advertisement, , 10. Which function among the following can’t be accessed outside the class in java in, same package?, a) public void show(), b) void show(), c) protected show(), d) static void show(), View Answer, Answer: c, Explanation: The protected members are available within the class. And are also available in, derived classes. But these members are treated as private members for outside the class and, inheritance structure. Hence can’t be accessed., 11. If private members are to be called outside the class, which is a good alternative?, a) Call a public member function which calls private function, b) Call a private member function which calls private function, c) Call a protected member function which calls private function, d) Not possible, View Answer, Answer: a, Explanation: The private member functions can be accessed within the class. A public, member function can be called which in turn calls the private member function. This, maintains the security and adheres to the rules of private members., 12. A private function of a derived class can be accessed by the parent class., a) True
Page 235 :
b) False, View Answer, Answer: b, Explanation: If private functions get accessed even by the parent class that will violate the, rules of private members. If the functions can be accessed then the derived class security is, hindered., 13. Which error will be produced if private members are accessed?, a) Can’t access private message, b) Code unreachable, c) Core dumped, d) Bad code, View Answer, Answer: a, Explanation: The private members access from outside the class produce an error. The error, states that the code at some line can’t access the private members. And denies the access, terminating the program., advertisement, , 14. Can main() function be made private?, a) Yes, always, b) Yes, if program doesn’t contain any classes, c) No, because main function is user defined, d) No, never, View Answer, Answer: d, Explanation: The reason given in option “No, because main function is user defined― is, wrong. The proper reason that the main function should not be private is that it should be, accessible in whole program. This makes the program flexible., 15. If a function in java is declared private then it __________________, a) Can’t access the standard output, b) Can access the standard output, c) Can’t access any output stream, d) Can access only the output streams, View Answer, Answer: b, Explanation: The private members can access any standard input or output. There is no, restriction on access to any input or output stream. And since standard input can also be used, hence only accessing the output stream is not true., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming, here is complete set of 1000+ Multiple, Choice Questions and Answers.
Page 236 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Constant Member, Functions, » Next - Object Oriented Programming Questions and Answers – Public Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Constant Member Functions, Object Oriented Programming Questions and Answers – Public Member Functions, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on String Handling, 2. C# Programming Examples, 3. C Programming Examples on Linked List, 4. C# Programming Examples on Files, 5. Java Programming Examples, 6. Java Programming Examples on Exception Handling, 7. C# Programming Examples on Exceptions, 8. C Programming Examples on Strings, 9. Java Programming Examples on Collections, 10. Java Programming Examples on Multithreading, 11. Java Programming Examples on File Handling, 12. C# Programming Examples on Inheritance, 13. C# Basic Programming Examples, 14. Java Programming Examples on Java.Lang, 15. Java Programming Examples on Mathematical Functions, 16. C Programming Examples on Mathematical Functions, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Functions, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Public Member Functions, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Public Member Functions―.
Page 237 :
1. What are public member functions?, a) Functions accessible outside the class but not in derived class, b) Functions accessible outside the class directly, c) Functions accessible everywhere using object of class, d) Functions that can’t be accessed outside the class, View Answer, Answer: c, Explanation: The most suitable definition would be that public member functions are, accessible everywhere using object of the class. If derived classes are using those, derived, class object can be used to call those functions., advertisement, , 2. Which among the following is true for public member functions?, a) Public member functions doesn’t have a return type, b) Public member functions doesn’t have any security, c) Public member functions are declared outside the class, d) Public member functions can be called using object of class, View Answer, Answer: d, Explanation: The public member functions can be called using object of the class. The, members can’t be declared outside the class as those would become non-member, functions of the class. The functions have security as those can be accessed using the class, object only., 3. Which type of member functions get inherited in the same specifier in which the, inheritance is done? (If private inheritance is used, those become private and if public used,, those become public), a) Private member functions, b) Protected member functions, c) Public member functions, d) All member functions, View Answer, Answer: c, Explanation: The public member functions gets into the same specifier in which the, inheritance is done. If protected members are involved in public inheritance, still those, remain protected in the derived class but public members become public on public, inheritance and protected in protected inheritance., 4. Which syntax among the following is correct for public member functions?, a) public::void functionName(parameters), b) public void functionName(parameters), c) public(void functionName(parameters)), d) public:-void functionName(Parameters), View Answer, Answer: b, Explanation: The public member functions declaration must be mentioned with the keyword
Page 238 :
public. The syntax given is used in java. Keyword public is followed by the usual function, declaration., 5. Which syntax is applicable to declare public member functions in C++?, a) public: <function declaration>, b) public(<function declaration>), c) public void <function declaration>, d) public::<function declaration>, View Answer, Answer: a, Explanation: The syntax in C++ must contain the public keyword followed by a colon., Thereafter, all the public members can be declared. But in few other language, public have to, be mentioned explicitly with each member., advertisement, , 6. In java, which rule among the following is applicable?, a) Keyword public can’t be preceded with all the public members, b) Keyword public must be preceded with all the public members, c) Keyword public must be post mentioned the function declaration, d) Keyword public is not mandatory, View Answer, Answer: b, Explanation: The public members in java must be preceded with the keyword public. It must, be mentioned with each public member, unlike C++ where we mention it only once. In java,, each member must have explicit declaration of specifier type., 7. How many public members are allowed in a class?, a) Only 1, b) At most 7, c) Exactly 3, d) As many as required, View Answer, Answer: d, Explanation: The number of public members that can be defined in a class doesn’t have, any limit. Though the programmer should not use too many functions, instead should use, another class for more specific functions to reduce the readability complexity., 8. Which is not a proper way to access public members of a class?, a) Using object pointer with arrow operator, b) Using object of class in main function, c) Using object of class with arrow operator, d) Using object anywhere in the program, View Answer, Answer: c, Explanation: The public members can be accessed anywhere in the program using the object
Page 239 :
of the class. And if object pointer is used, then arrow operator is used to access class, members. If normal object is used with arrow operator, an error will be generated., 9. Which call is correct for public members of a nested class?, a) Can be called from object of enclosing class, b) Can be called within enclosing class only with direct names, c) Direct names should be used for the nested classes, d) Only with help of nested class object pointer, View Answer, Answer: a, Explanation: The closest definition is that any public member function of the nested class can, be accessed with the help of enclosing class object. The nested class object pointer can be, used only within the enclosing class. It’s not mandatory to use the members of nested, class only within the enclosing class., advertisement, , 10. Which public function call among the following is correct outside the class, if return type, is void (C++)?, a) object.void functionName(parameters);, b) object.functionName(parameters);, c) object.functionName void (parameters), d) object.void functionName();, View Answer, Answer: b, Explanation: The condition given says that there is no return type hence we can call the, function directly. The object name should be mentioned with a dot operator to access its class, members. Then the function name with parameters, if required, can be given., 11. If public members are to be restricted from getting inherited from the subclass of the class, containing that function, which alternative is best?, a) Make the function private, b) Use private inheritance, c) Use public inheritance, d) Use protected inheritance, View Answer, Answer: b, Explanation: If private inheritance is used then the class containing the function will be able, to use the function with rules of whichever specifier is used. Then the derived class makes, those function the private members of itself. This restricts the public members of parent class, from further inheritance., 12. A derived class object can access the public members of the base class., a) True, b) False, View Answer
Page 240 :
Answer: b, Explanation: The public members of the base class can be accessed from the derived class, object only if public inheritance is used. If protected or private inheritance is used then those, members become public/protected in derived class and hence won’t be able to be called, from object of the derived class., 13. If a class have a public member function and is called directly in the main function then, ___________________________, a) Undeclared function error will be produced, b) Out of memory error is given, c) Program gives warning only, d) Program shut down the computer, View Answer, Answer: a, Explanation: If the function is called directly without using any object then the compiler, doesn’t gets to know that the function have to be called from a specific class. And if there, are no global or in-scope function with same name then the compiler produces an error, stating that the called function is undeclared., advertisement, , 14. The function main() must always be public., a) True, b) False, View Answer, Answer: a, Explanation: The main() function must always be public. This is because the whole function, and the operating system that is out of the package have to access the main function, throughout the program execution. Hence the main() function should be public so as to be, available everywhere in the program., 15. All the public member functions ___________________, a) Can’t access the private members of a class, b) Can’t access the protected members of a class, c) Can access only public members of a class, d) Can access all the member of its class, View Answer, Answer: d, Explanation: The public member function can access any private, protected and public, member of its class. Not only public member function, any member function of a class can, access each and every other member declared inside the class. Hence are flexible to program., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers.
Page 241 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Private Member, Functions, » Next - Object Oriented Programming Questions and Answers – Exception Handling, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Private Member Functions, Object Oriented Programming Questions and Answers – Exception Handling, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Strings, 2. C# Questions and Answers, 3. C# Programming Examples on Files, 4. C Programming Examples on Linked List, 5. C++ Questions and Answers, 6. C# Programming Examples on Exceptions, 7. Java Programming Examples on Multithreading, 8. Java Programming Examples on Collections, 9. Java Programming Examples on Java.Lang, 10. Ruby Programming Questions and Answers, 11. C# Programming Examples, 12. Java Programming Examples, 13. C# Basic Programming Examples, 14. Java Programming Examples on Mathematical Functions, 15. C Programming Examples on Mathematical Functions, 16. C# Programming Examples on Functions, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Inheritance, 19. Java Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Exception Handling, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Exception Handling―.
Page 242 :
1. What is an exception?, a) Problem arising during compile time, b) Problem arising during runtime, c) Problem in syntax, d) Problem in IDE, View Answer, Answer: b, Explanation: The problems that might occur during execution of a program are known as, exceptions. The exceptions are unexpected sometimes and can be predicted. Also, the, exceptions should be always considered for a better program., advertisement, , 2. Why do we need to handle exceptions?, a) To prevent abnormal termination of program, b) To encourage exception prone program, c) To avoid syntax errors, d) To save memory, View Answer, Answer: a, Explanation: The exceptions should be handled to prevent any abnormal termination of a, program. The program should keep running even if it gets interrupted in between. The, program should preferable show the error occurred and then retry the process or just continue, the program further., 3. An exception may arise when _______________, a) Input is fixed, b) Input is some constant value of program, c) Input given is invalid, d) Input is valid, View Answer, Answer: c, Explanation: The exceptions may arise because the input given by the user might not be of, the same type that a program can manage. If the input is invalid the program gets terminated., 4. If a file that needs to be opened is not found in the target location then _____________, a) Exception will be produced, b) Exceptions are not produced, c) Exception might get produced because of syntax, d) Exceptions are not produced because of logic, View Answer, Answer: a, Explanation: The exceptions are produced when anything unexpected happened. The, program might not be able to find a file in the target location and hence program produces an, exceptions. The exception produced, then terminates the program.
Page 243 :
5. Which is the universal exception handler class?, a) Object, b) Math, c) Errors, d) Exceptions, View Answer, Answer: d, Explanation: Any type of exception can be handled by using class Exceptions. An object of, this class is created which can manipulate the exception data. The data can be used to display, the error or to run the program further based on error produced., advertisement, , 6. What are two exception classes in hierarchy of java exceptions class?, a) Runtime exceptions only, b) Compile time exceptions only, c) Runtime exceptions and other exceptions, d) Other exceptions, View Answer, Answer: c, Explanation: The exceptions class is having two other derived classes which are of runtime, exception handler and for other type of exceptions handling. The runtime exception handler is, used to handle the exceptions produced during run time and same with case of other, exceptions., 7. Which are the two blocks that are used to check error and handle the error?, a) Try and catch, b) Trying and catching, c) Do and while, d) TryDo and Check, View Answer, Answer: a, Explanation: Two blocks that are used to check for errors and to handle the errors are try and, catch block. The code which might produce some exceptions is placed inside the try block, and then the catch block is written to catch the error that is produced. The error message or, any other processing can be done in catch block if the error is produced., 8. There can be a try block without catch block but vice versa is not possible., a) True, b) False, View Answer, Answer: a, Explanation: The try block may or may not have any catch block. But a catch block can’t, be there in a program if there is no try block. It is like else-block can only be written if and, only if if-block is present in the program.
Page 244 :
9. How many catch blocks can a single try block can have?, a) Only 1, b) Only 2, c) Maximum 127, d) As many as required, View Answer, Answer: d, Explanation: There is no limit on the number of catch blocks corresponding to a try block., This is because the error can be of any type and for each type, a new catch block can be, defined. This is to make sure all type of exceptions can be handled., advertisement, , 10. Which among the following is not a method of Throwable class?, a) public String getMessage(), b) public Throwable getCause(), c) public Char toString(), d) public void printStackTrace(), View Answer, Answer: c, Explanation: Actually all the functions are available in throwable class. But the return type, given in the option is wrong. The function toString returns string value. Hence the return type, must be a String and not a char., 11. To catch the exceptions ___________________, a) An object must be created to catch the exception, b) A variable should be created to catch the exception, c) An array should be created to catch all the exceptions, d) A string have to be created to store the exception, View Answer, Answer: a, Explanation: The object must be created of a specific class of which the error has occurred. If, the type of error is unknown then we can use an object of class Exceptions. This object will, be able to handle any kind of exception that a program might produce., 12. Multiple catch blocks __________________, a) Are mandatory for each try block, b) Can be combined into a single catch block, c) Are not possible for a try block, d) Can never be associated with a single try block, View Answer, Answer: b, Explanation: The separate catch blocks for a single try block can be combined into a single, catch block. All type of errors can be then handled in s single block. The type still have to be, specified for the errors that might be produced.
Page 245 :
13. Which symbol should be used to separate the type of exception handler classes in a single, catch block?, a) ?, b) ,, c) –, d) |, View Answer, Answer: d, Explanation: A pipe symbol can be used to separate different type of exceptions. The, exceptions should always be given in proper sequence to ensure that no code remains, unreachable. If not done properly the code might never be used in a program., advertisement, , 14. Which class is used to handle the input and output exceptions?, a) InputOutput, b) InputOutputExceptions, c) IOExceptions, d) ExceptionsIO, View Answer, Answer: c, Explanation: There is a specific class to handle each type of exceptions that might be, produced in a program. The input and output exceptions can be handled by an object of class, IOExcceptions. This class handles all type of input and output exceptions., 15. Why do we use finally block?, a) To execute the block if exception occurred, b) To execute a code when exception is not occurred, c) To execute a code whenever required, d) To execute a code with each and every run of program, View Answer, Answer: d, Explanation: Sometimes there is a need to execute a set of code every time the program runs., Even if the exception occurs and even if it doesn’t, there can be some code that must be, executed at end of the program. That code is written in finally block. This block is always, executed regardless of exceptions occurring., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Page 246 :
« Prev - Object Oriented Programming Questions and Answers – Public Member, Functions, » Next - Object Oriented Programming Questions and Answers – Catching Class Types, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Public Member Functions, Object Oriented Programming Questions and Answers – Catching Class Types, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Arrays, 2. C Programming Examples without using Recursion, 3. Java Programming Examples on Java.Lang, 4. Java Programming Examples on Networking, 5. Java Programming Examples on Collections, 6. C# Programming Examples on Events, 7. C# Programming Examples on Inheritance, 8. Ruby Programming Questions and Answers, 9. Java Programming Examples on Inheritance, 10. C# Programming Examples, 11. Java Programming Examples on Classes, 12. Java Programming Examples on Multithreading, 13. Java Programming Examples, 14. C Programming Examples on File Handling, 15. Java Programming Examples on String Handling, 16. Java Programming Examples on Event Handling, 17. Java Programming Examples on File Handling, 18. C# Programming Examples on Exceptions, 19. Object Oriented Programming Questions and Answers, 20. Object Oriented Programming Questions and Answers – Inbuilt Classes, advertisement, , Object Oriented Programming Questions, and Answers – Catching Class Types, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Catching Class Types―., 1. Which among the following is true for class exceptions?, a) Only base class can give rise to exceptions, b) Only derived class can give rise to exceptions, c) Either base class or derived class may produce exceptions, d) Both base class and derived class may produce exceptions, View Answer
Page 247 :
Answer: d, Explanation: It’s not mandatory that either base class or derived class can give rise to, exceptions. The exceptions might get produced from any class. The exceptions depends on, code., advertisement, , 2. If both base and derived class caught exceptions ______________, a) Then catch block of derived class must be defined before base class, b) Then catch block of base class must be defined before the derived class, c) Then catch block of base and derived classes doesn’t matter, d) Then catch block of base and derived classes are not mandatory to be defined, View Answer, Answer: a, Explanation: It is a condition for writing the catch blocks for base and derived classes. It is, mandatory to write derived class catch block first because the errors produced by the derived, class must be handled first., 3. Which among the following is true?, a) If catch block of base class is written first, it is compile time error, b) If catch block of base class is written first, it is run time error, c) If catch block of base class is written first, derived class catch block can’t be reached, d) If catch block of base class is written first, only derived class catch block is executed, View Answer, Answer: c, Explanation: If the catch block of the base class is defined first and then the derived class, catch block is given. The code becomes unreachable. Hence the derived class catch block, must be written first., 4. The catching of base class exception ___________________________ in java., a) After derived class is not allowed by compiler, b) Before derived class is not allowed by compiler, c) Before derived class is allowed, d) After derived class can’t be done, View Answer, Answer: b, Explanation: The catching of base class exception before derived class is not allowed in java., The compiler itself doesn’t allow this declaration. It produces an error., 5. If catching of base class exception is done before derived class in C++ ________________, a) It gives compile time error, b) It doesn’t run the program, c) It may give warning but not error, d) It always gives compile time error, View Answer, Answer: c, Explanation: The compiler in C++ doesn’t identify this as compile time error and allows
Page 248 :
the execution of the program. But, the compiler may give some warning related to the catch, block sequence or code unreachable., advertisement, , 6. How many catch blocks can a class have?, a) Only 1, b) 2, c) 3, d) As many as required, View Answer, Answer: d, Explanation: There are many type of exceptions that may arise while running a code. And, each catch block can handle only one exception. Hence there can be as many catch blocks as, required., 7. Since which version of java is multiple exception catch was made possible?, a) Java 4, b) Java 5, c) Java 6, d) Java 7, View Answer, Answer: d, Explanation: None of the languages used to support multiple exception catch in a single catch, block. Since java 7 the feature was added to catch more than one exceptions in one catch, block., 8. To catch more than one exception in one catch block, how are the exceptions separated in, the syntax?, a) Vertical bar, b) Hyphen, c) Plus, d) Modulus, View Answer, Answer: a, Explanation: Just the way we separate the arguments in a function definition using comma., Here we separate the exceptions by using a vertical bar or we call it pipe symbol sometimes., This is just a convention followed to separate different exception list., 9. If a catch block accepts more than one exceptions then __________________, a) The catch parameters are not final, b) The catch parameters are final, c) The catch parameters are not defined, d) The catch parameters are not used, View Answer
Page 249 :
Answer: b, Explanation: The catch parameters are made final. This is to ensure that the parameters are, not changed inside the catch block. Hence those retain their values., advertisement, , 10. Which among the following handles the undefined class in program?, a) ClassNotFound, b) NoClassException, c) ClassFoundException, d) ClassNotFoundException, View Answer, Answer: d, Explanation: It is the exception handler that handles the exceptions when the class used is not, found in the program. This is done to handle all the undefined class exceptions. This can be, due to a command line error., 11. If classes produce some exceptions, then ______________________, a) Their respective catch block must be defined, b) Their respective catch blocks are not mandatory, c) Their catch blocks should be defined inside main function, d) Their catch blocks must be defined at the end of program, View Answer, Answer: a, Explanation: The catch blocks must be defined. This is to ensure that all the exceptions, related to the classes are handled by the program code and the program doesn’t terminate, unexpectedly., 12. Which among the following is true?, a) Only the base class catch blocks are important, b) Only the derived class catch blocks are important, c) Both the base and derived class catch blocks are important, d) If base and derived classes both produce exceptions, program doesn’t run, View Answer, Answer: c, Explanation: The purpose of exception handling is to handle the unexpected errors in the, program. If base class might produce some error then its catch block must be given and if the, derived class might produce some error then it must be given a specific catch block too., 13. Which is the necessary condition to define the base and derived class catch blocks?, a) Base class catch should be defined first, b) Derived class catch should be defined first, c) Catch block for both the classes must not be defined, d) Catch block must be defined inside main function, View Answer, Answer: b, Explanation: The derived class catch blocks must be defined prior to the base class catch
Page 250 :
block. This is to ensure that all the catch boxes are reachable. If not done, the code might, become unreachable which in turn makes the program prone to errors., advertisement, , 14. Only the base class catch box can handle more than one exception in single block., a) True, b) False, View Answer, Answer: b, Explanation: There is no specific condition that states that only base class catch box can, handle more than one exception in single box. Even the derived class catch clocks can handle, more than one exceptions., 15. Which condition among the following might result in memory exception?, a) False if conditions, b) Nested if conditions that are all false, c) Infinite loops, d) Loop that runs exactly 99 times, View Answer, Answer: c, Explanation: The infinite loops doesn’t stop running once started. There must be a way to, stop the loop but that is always an improper termination. Infinite loops may keep on using, more memory and hence would result in memory error., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Exception Handling, » Next - Object Oriented Programming Questions and Answers – Static Data Members, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Exception Handling, Object Oriented Programming Questions and Answers – Static Data Members, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Hard Graph Problems & Algorithms, 2. Java Programming Examples on Data-Structures, 3. Java Programming Examples on Utility Classes
Page 251 :
4. C# Programming Examples on Functions, 5. Java Programming Examples on Collections, 6. C++ Questions and Answers, 7. Java Programming Examples on Mathematical Functions, 8. Java Programming Examples on Java.Lang, 9. Java Programming Examples on Multithreading, 10. Java Programming Examples on Networking, 11. C# Programming Examples, 12. Ruby Programming Questions and Answers, 13. Java Programming Examples on Collection API, 14. Java Programming Examples on Classes, 15. Java Programming Examples on Inheritance, 16. Java Programming Examples, 17. C# Programming Examples on Inheritance, 18. C# Programming Examples on Exceptions, 19. Object Oriented Programming Questions and Answers, 20. Object Oriented Programming Questions and Answers – Polymorphism, advertisement, , Object Oriented Programming Questions, and Answers – Static Data Members, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Static Data Members―., 1. Which among the following best defines static variables members?, a) Data which is allocated for each object separately, b) Data which is common to all the objects of a class, c) Data which is common to all the classes, d) Data which is common to a specific method, View Answer, Answer: b, Explanation: The static data members are made common to all the object of a class. They, doesn’t change from object to object. Those are property of class rather than of any, individual object., advertisement, , 2. Which keyword should be used to declare static variables?, a) static, b) stat, c) common, d) const, View Answer
Page 252 :
Answer: a, Explanation: The keyword used to declare static variables is static. This is must be used while, declaring the static variables. The compiler can make variables static if and only if they are, mentioned with static keyword., 3. Any changes made to static data member from one member function _____________, a) Is reflected to only the corresponding object, b) Is reflected to all the variables in a program, c) Is reflected to all the objects of that class, d) Is constant to that function only, View Answer, Answer: c, Explanation: The changes made from any function to static data member will be a common, change for all the other objects also. If the change is made with respect to one object and, change is printed from another object, the result will be same., 4. Which is the correct syntax for declaring static data member?, a) static mamberName dataType;, b) dataType static memberName;, c) memberName static dataType;, d) static dataType memberName;, View Answer, Answer: d, Explanation: The syntax must firstly be mentioned with the keyword static. Then the data, type of the member followed by the member name should be given. This is general form of, declaring static data members., 5. The static data member ______________________, a) Must be defined inside the class, b) Must be defined outside the class, c) Must be defined in main function, d) Must be defined using constructor, View Answer, Answer: b, Explanation: The static data members must be defined outside the class. Since these are, common to all the objects and should be created only once, they must not be defined in the, constructor., advertisement, , 6. The syntax for defining the static data members is __________, a) dataType className :: memberName = value;, b) dataType className : memberName = value;, c) dataType className . memberName = value;, d) dataType className -> memberName =value;, View Answer
Page 253 :
Answer: a, Explanation: The syntax doesn’t contain the static keyword. Since it is already been, declared as static inside the class. The data type and the corresponding class name must be, there to allocate the variable to a class. The value is assigned using scope resolution operator, for the member name., 7. If static data members have to be used inside a class, those member functions, _______________, a) Must not be static member functions, b) Must not be member functions, c) Must be static member functions, d) Must not be member function of corresponding class, View Answer, Answer: c, Explanation: Only the static member functions can access the static data members. The, definition of static members is made common and hence the member function should be, capable of manipulating the static data members., 8. The static data member __________________________, a) Can be accessed directly, b) Can be accessed with any public class name, c) Can be accessed with dot operator, d) Can be accessed using class name if not using static member function, View Answer, Answer: d, Explanation: The static data members can be accessed using the class name also. If the, member functions is not used or is not to be used then we can call the static data members, directly by using its corresponding class name., 9. Which among the following is the correct syntax to access static data member without, using member function?, a) className -> staticDataMember;, b) className :: staticDataMember;, c) className : staticDataMember;, d) className . staticDataMember;, View Answer, Answer: b, Explanation: For accessing the static data members without using the static member, functions, the class name can be used. The class name followed by scope resolution,, indicating that static data members is member of this class, and then the data member name., 10. Which data members among the following are static by default?, a) extern, b) integer, c) const, d) void, View Answer
Page 254 :
Answer: c, Explanation: The const data members of any class are made static by default. This is an, implicit meaning given by the compiler to the member. Since const values won’t change, from object to object, hence are made static instead., advertisement, , 11. What is the output of the following program?, class Test, {, private:, static int x;, public: static void fun(), {, cout << ++x << “ ―;, }, };, int Test :: x =20;, void main(), {, Test x;, x.fun();, x.fun();, }, , a) 20 22, b) 20 21, c) 21 22, d) 22 23, View Answer, Answer: c, Explanation: The static member is initialized with 20. Then the function is called which used, pre-increment and printed value of x. The function is called twice. Hence we get 21 22 as, output., 12. Whenever any static data member is declared in a class ______________________, a) Only one copy of the data is created, b) New copy for each object is created, c) New memory location is allocated with each object, d) Only one object uses the static data, View Answer, Answer: a, Explanation: The static data is same for all the objects. Instead of creating the same data each, time an object is created, the compiler created only one data which is accessed by all the, objects of the class. This saves memory and reduces redundancy., 13. If object of class are created, then the static data members can be accessed ____________, a) Using dot operator, b) Using arrow operator, c) Using colon, d) Using dot or arrow operator, View Answer
Page 255 :
Answer: d, Explanation: The static data members can be accessed in usual way as other members are, accessed using the objects. The dot operator is used generally. Arrow can be used with the, pointers., advertisement, , 14. What will be the output of the following program?, class Test, {, public: Test(), {, cout << "Test's Constructor is Called " <<, endl;, }, };, class Result, {, static Test a;, public:, Result(), {, cout << "Result's Constructor is Called " <<, endl;, }, };, void main(), {, Result b;, }, , a) Test’s Constructor is Called, b) Result’s Constructor is Called, c) Result’s Constructor Called Test’s Constructor is Called, d) Test’s Constructor Called Result’s Constructor is Called, View Answer, Answer: b, Explanation: The output is the message printed from the constructor of class Result. There is, no inheritance used hence only one constructor is called. Since static members are declared, once in class declaration and are not defined. The constructor of class Test will not be called., 15. Which among the following is wrong syntax related to static data members?, a) className :: staticDataMember;, b) dataType className :: memberName =value;, c) static dataType memberName;, d) className : dataType -> memberName;, View Answer, Answer: d, Explanation: The syntax given in option d doesn’t belong to any particular declaration or
Page 256 :
definition. First one is to access the static members using the class name. Second is to define, the static data outside the class. Third syntax id to declare a data member as static in a class., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Catching Class Types, » Next - Object Oriented Programming Questions and Answers – Static Member, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Catching Class Types, Object Oriented Programming Questions and Answers – Static Member Functions, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples on Mathematical Functions, 2. Programming Questions and Answers, 3. Python Programming Examples on Linked Lists, 4. Data Science Questions and Answers, 5. C Programming Examples on Linked List, 6. Java Programming Examples on Utility Classes, 7. Java Programming Examples on Collections, 8. Java Programming Examples, 9. C# Programming Examples on Functions, 10. Java Programming Examples on Java.Lang, 11. Java Programming Examples on File Handling, 12. Java Programming Examples on Multithreading, 13. C# Programming Examples on Data Structures, 14. C++ Programming Examples on Data-Structures, 15. C# Programming Examples on Mathematics, 16. Java Programming Examples on Data-Structures, 17. C Programming Examples on Data-Structures, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement
Page 257 :
Object Oriented Programming Questions, and Answers – Static Member Functions, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Static Member Functions―., 1. Which among the following is correct definition for static member functions?, a) Functions created to allocate constant values to each object, b) Functions made to maintain single copy of member functions for all objects, c) Functions created to define the static members, d) Functions made to manipulate static programs, View Answer, Answer: b, Explanation: The functions which are made common, with respect to definition and data, usage, to all the objects. These functions are able to access the static data members of a class., advertisement, , 2. The static member functions __________________, a) Have access to all the members of a class, b) Have access to only constant members of a class, c) Have access to only the static members of a class, d) Have direct access to all other class members also, View Answer, Answer: c, Explanation: The static member functions are common for all the objects. These functions, can use only the static members of a class in which those are defined. This is because other, members change with respect to each object created., 3. The static member functions ____________________, a) Can be called using class name, b) Can be called using program name, c) Can be called directly, d) Can’t be called outside the function, View Answer, Answer: a, Explanation: The static members can be accessed using class name also. This is because the, static members remain common to all the objects. Hence objects are not required., 4. Which is correct syntax to access the static member functions with class name?, a) className . functionName;, b) className -> functionName;, c) className : functionName;
Page 258 :
d) className :: functionName;, View Answer, Answer: d, Explanation: The scope resolution operator must be used to access the static member, functions with class name. This indicates that the function belongs to the corresponding class., 5. Which among the following is not applicable for the static member functions?, a) Variable pointers, b) void pointers, c) this pointer, d) Function pointers, View Answer, Answer: c, Explanation: Since the static members are not property of objects, they doesn’t have this, pointer. Every time the same member is referred from all the objects, hence use of this, pointer is of no use., advertisement, , 6. Which among the following is true?, a) Static member functions can’t be virtual, b) Static member functions can be virtual, c) Static member functions can be declared virtual if it is pure virtual class, d) Static member functions can be used as virtual in Java, View Answer, Answer: a, Explanation: The static member functions can’t be virtual. This is a restriction on static, member functions, since the definition should not change or should not be overridden by any, other function of derived class. The static members must remain same for all the objects., 7. The static members are ______________________, a) Created with each new object, b) Created twice in a program, c) Created as many times a class is used, d) Created and initialized only once, View Answer, Answer: d, Explanation: The static members are created only once. Then those members are reused, whenever called or invoked. Memory is allocated only once., 8. Which among the following is true?, a) Static member functions can be overloaded, b) Static member functions can’t be overloaded, c) Static member functions can be overloaded using derived classes, d) Static member functions are implicitly overloaded, View Answer
Page 259 :
Answer: b, Explanation: The static member functions can’t be overloaded because the definition, must be the same for all the instances of a class. If an overloaded function have many, definitions, none of them can be made static., 9. The static member functions _______________, a) Can’t be declared const, b) Can’t be declared volatile, c) Can’t be declared const or volatile, d) Can’t be declared const, volatile or const volatile, View Answer, Answer: d, Explanation: The static member functions can’t be made const, since any object or class, itself should be capable of making changes to the function. And the function must retain all, changes common to all the objects., advertisement, , 10. Which keyword should be used to declare the static member functions?, a) static, b) stat, c) const, d) common, View Answer, Answer: a, Explanation: The member functions which are to be made static, must be preceded with the, keyword static. This indicates the compiler to make the functions common to all the objects., And a new copy is not created with each of the new object., 11. The keyword static is used _______________, a) With declaration inside class and with definition outside the class, b) With declaration inside class and not with definition outside the class, c) With declaration and definition wherever done, d) With each call to the member function, View Answer, Answer: b, Explanation: The keyword is used only inside the class while declaring the static member., Outside the class, only definition with proper syntax is given. There is no need of specifying, the keyword static again., 12. Which among the following can’t be used to access the members in any way?, a) Scope resolution, b) Arrow operator, c) Single colon, d) Dot operator, View Answer
Page 260 :
Answer: c, Explanation: The single colon can’t be used in any way in order to access the static, members of a class. Other symbols can be used according to the code and need., 13. We can use the static member functions and static data member __________________, a) Even if class object is not created, b) Even if class is not defined, c) Even if class doesn’t contain any static member, d) Even if class doesn’t have complete definition, View Answer, Answer: a, Explanation: The static members are property of class as a whole. There is no need of, specific objects to call static members. Those can be called directly or with class name., advertisement, , 14. The static data member _________________, a) Can be mutable, b) Can’t be mutable, c) Can’t be integer, d) Can’t be characters, View Answer, Answer: b, Explanation: The static data members can never be mutable. There copies are not made., Since those are common and created only once., 15. If static data member are made inline, ______________, a) Those should be initialized outside the class, b) Those can’t be initialized with the class, c) Those can be initialized within the class, d) Those can’t be used by class members, View Answer, Answer: c, Explanation: Since the members are created once and are common for all the instances, those, can be initialized inside the class. Those doesn’t change with each object being created, hence can be defined inside the class once for all., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Page 261 :
« Prev - Object Oriented Programming Questions and Answers – Static Data Members, » Next - Object Oriented Programming Questions and Answers – Passing Object to, Functions, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Static Data Members, Object Oriented Programming Questions and Answers – Passing Object to Functions, advertisement, advertisement, , Recommended Posts:, 1. C# Basic Programming Examples, 2. Python Programming Examples, 3. Java Programming Examples on Utility Classes, 4. C# Programming Examples on Files, 5. Python Programming Examples on Linked Lists, 6. R Programming Questions and Answers, 7. Ruby Programming Questions and Answers, 8. C Programming Examples on Linked List, 9. Java Programming Examples on String Handling, 10. Java Programming Examples, 11. Java Programming Examples on File Handling, 12. Java Programming Examples on Mathematical Functions, 13. Java Programming Examples on Collections, 14. Java Programming Examples on Multithreading, 15. C Programming Examples on Mathematical Functions, 16. Java Programming Examples on Java.Lang, 17. Java Programming Examples on Inheritance, 18. C# Programming Examples on Functions, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Passing Object to, Functions, « Prev, Next », , This set of Object Oriented Programming Interview Questions and Answers for Experienced, people focuses on “Passing Object to Functions―., 1. Passing object to a function _______________, a) Can be done only in one way, b) Can be done in more than one ways, c) Is not possible
Page 262 :
d) Is not possible in OOP, View Answer, Answer: b, Explanation: The objects can be passed to the functions and this requires OOP concept, because objects are main part of OOP. The objects can be passed in more than one way to a, function. The passing depends on how the object have to be used., advertisement, , 2. The object ________________, a) Can be passed by reference, b) Can be passed by value, c) Can be passed by reference or value, d) Can be passed with reference, View Answer, Answer: c, Explanation: The objects can be passed by reference if required to use the same object. The, values can be passed so that the main object remains same and no changes are made to it if, the function makes any changes to the values being passed., 3. Which symbol should be used to pass the object by reference in C++?, a) &, b) @, c) $, d) $ or &, View Answer, Answer: a, Explanation: The object to be passed by reference to the function should be preceded by &, symbol in the argument list syntax of the function. This indicates the compiler not to use new, object. The same object which is being passed have to be used., 4. If object is passed by value ______________, a) Copy constructor is used to copy the values into another object in the function, b) Copy constructor is used to copy the values into temporary object, c) Reference to the object is used to access the values of the object, d) Reference to the object is used to created new object in its place, View Answer, Answer: a, Explanation: The copy constructor is used. This constructor is used to copy the values into a, new object which will contain all the values same as that of the object being passed but any, changes made to the newly created object will not affect the original object., 5. Pass by reference of an object to a function _______________, a) Affects the object in called function only, b) Affects the object in prototype only, c) Affects the object in caller function
Page 263 :
d) Affects the object only if mentioned with & symbol with every call, View Answer, Answer: c, Explanation: The original object in the caller function will get affected. The changes made in, the called function will be same in the caller function object also., advertisement, , 6. Copy constructor definition requires __________________, a) Object to be passed by value, b) Object not to be passed to it, c) Object to be passed by reference, d) Object to be passed with each data member value, View Answer, Answer: c, Explanation: The object must be passed by reference to a copy constructor. This is to avoid, the out of memory error. The constructors keeps calling itself, if not passed by reference, and, goes out of memory., 7. What is the type of object that should be specified in the argument list?, a) Function name, b) Object name itself, c) Caller function name, d) Class name of object, View Answer, Answer: d, Explanation: The type of object is the class itself. The class name have to be specified in, order to pass the objects to a function. This allows the program to create another object of, same class or to use the same object that was passed., 8. If an object is passed by value, _________________, a) Temporary object is used in the function, b) Local object in the function is used, c) Only the data member values are used, d) The values are accessible from the original object, View Answer, Answer: b, Explanation: When an object is called by values, copy constructor is called and object is, copied to the local object of the function which is mentioned in the argument list. The values, gets copied and are used from the local object. There is no need to access the original object, again., 9. Can data members be passed to a function using the object?, a) Yes, it can be passed only inside class functions, b) Yes, only if the data members are public and are being passed to a function outside the, class, c) No, can’t be passed outside the class
Page 264 :
d) No, can’t be done, View Answer, Answer: b, Explanation: The data members can be passed with help of object but only if the member is, public. The object will obviously be used outside the class. The object must have access to, the data member so that its value or reference is used outside the class which is possible only, if the member is public., 10. What exactly is passed when an object is passed by reference?, a) The original object name, b) The original object class name, c) The exact address of the object in memory, d) The exact address of data members, View Answer, Answer: c, Explanation: The location of the object, that is, the exact memory location is passed, when, the object is passed by reference. The pass by reference is actually a reference to the object, that the function uses with another name to the same memory location as the original object, uses., advertisement, , 11. If the object is not to be passed to any function but the values of the object have to be, used then?, a) The data members should be passed separately, b) The data members and member functions have to be passed separately, c) The values should be present in other variables, d) The object must be passed, View Answer, Answer: a, Explanation: The data members can be passed separately. There is no need to pass whole, object, instead we can use the object to pass only the required values., 12. Which among the following is true?, a) More than one object can’t be passed to a function, b) Any number of objects can be passed to a function, c) Objects can’t be passed, only data member values can be passed, d) Objects should be passed only if those are public in class, View Answer, Answer: b, Explanation: There is no restriction on passing the number of objects to a function. The, operating system or the compiler or environment may limit the number of arguments. But, there is no limit on number of objects till that limit., 13. What will be the output if all necessary code is included (Header files and main, function)?
Page 265 :
void test (Object &y), {, y = "It is a string";, }, void main(), {, Object x = null;, test (x);, System.out.println (x);, }, , a) Run time error, b) Compile time error, c) Null, d) It is a string, View Answer, Answer: d, Explanation: This is because the x object is passed by reference. The changes made inside the, function will be applicable to original function too., advertisement, , 14. In which type is new memory location will be allocated?, a) Only in pass by reference, b) Only in pass by value, c) Both in pass by reference and value, d) Depends on the code, View Answer, Answer: b, Explanation: The new memory location will be allocated only if the object is passed by value., Reference uses the same memory address and is denoted by another name also. But in pass, by value, another object is created and new memory space is allocated for it., 15. Pass by reference and pass by value can’t be done simultaneously in a single function, argument list., a) True, b) False, View Answer, Answer: b, Explanation: There is no condition which specifies that only the reference pass or values pass, is allowed. The argument list can contain one reference pass and another value pass. This, helps to manipulate the objects with functions more easily., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Interviews, here is complete set of, 1000+ Multiple Choice Questions and Answers.
Page 266 :
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Static Member, Functions, » Next - Object Oriented Programming Questions and Answers – Returning Objects, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Static Member Functions, Object Oriented Programming Questions and Answers – Returning Objects, advertisement, advertisement, , Recommended Posts:, 1. R Programming Questions and Answers, 2. C# Programming Examples on Mathematics, 3. C Programming Examples on File Handling, 4. Java Programming Examples on Multithreading, 5. C Programming Examples on Linked List, 6. Ruby Programming Questions and Answers, 7. C Programming Examples on Strings, 8. Java Programming Examples on Collections, 9. Java Programming Examples, 10. C Programming Examples on Stacks & Queues, 11. C# Programming Examples on Files, 12. C# Programming Examples on Arrays, 13. Java Programming Examples on Mathematical Functions, 14. Java Programming Examples on File Handling, 15. C Programming Examples on Mathematical Functions, 16. Java Programming Examples on Java.Lang, 17. Java Programming Examples on Inheritance, 18. Java Programming Examples on Classes, 19. C# Programming Examples on Functions, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Returning Objects, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Returning Objects―.
Page 267 :
1. In which of the following way(s) can the object be returned from a function?, a) Can only be returned by value, b) Can only be returned by reference, c) Can be returned either by value or reference, d) Can neither be returned by value nor by reference, View Answer, Answer: c, Explanation: The objects can be returned either by value or reference. There is no mandatory, condition for the way it should be used. The way of returning object can be decided based on, the requirement., advertisement, , 2. Whenever an object is returned by value ____________________, a) A temporary object is created, b) Temporary object is not created, c) Temporary object may or may not be created, d) New permanent object is created, View Answer, Answer: a, Explanation: A temporary object is created when an object is returned by value. The, temporary object is used to copy the values to another object or to be used in some way. The, object holds all the values of the data members of the object., 3. Where the temporary objects (created while return by value) are created?, a) Outside the function scope, b) Within the function, c) Inside the main function, d) Inside the calling function, View Answer, Answer: b, Explanation: The temporary object are created within the function and are intended to return, the value for specific use. Either the object can be assigned to another object or be used, directly if possible., 4. Which is the correct syntax for returning an object by value?, a) void functionName ( ){ }, b) object functionName( ) { }, c) class object functionName( ) { }, d) ClassName functionName ( ){ }, View Answer, Answer: d, Explanation: The class name itself should be the return type of the function. This notifies that, the function will return an object of specified class type. Only the class name should be, specified.
Page 268 :
5. Which is the correct syntax for defining a function which passes an object by reference?, a) className& functionName ( ), b) className* functionName( ), c) className-> functionName( ), d) &className functionName(), View Answer, Answer: a, Explanation: The function declaration must contain the class name as return type. But, a &, symbol should be followed by the class name. & indicates that the object being returned will, be returned by reference., advertisement, , 6. If an object is declared inside the function then ____________________ outside the, function., a) It can be returned by reference, b) It can’t be returned by reference, c) It can be returned by address, d) It can’t be returned at all, View Answer, Answer: b, Explanation: The object which is declared inside the class can never be returned by reference., This is because the object will be destroyed as it goes out of scope when the function is, returned. The local variables get destroyed when function is returned hence the local objects, can’t be returned by reference., 7. How many independent objects can be returned at same time from a function?, a) 1, b) 2, c) 3, d) 4, View Answer, Answer: a, Explanation: Only one object can be returned at a time. This is because a function is only, capable of returning a single value at a time. Though array of objects can be returned from a, function., 8. Which error will be produced if a local object is returned by reference outside a function?, a) Out of memory error, b) Run time error, c) Compile time error, d) No error, View Answer, Answer: c, Explanation: If the local object is returned outside the function then the compile-time error, arises. While the program is being converted and the processes happening during compile, time, the compiler won’t be able to resolve the statement.
Page 269 :
9. If object is passed by reference ____________________, a) Temporary object is created, b) Temporary object is created inside the function, c) Temporary object is created for few seconds, d) Temporary object is not created, View Answer, Answer: d, Explanation: The temporary object is not created. If object is returned by reference, a, particular memory location will be denoted with another name and hence same address, values will be used., advertisement, , 10. Which among the following is correct?, a) Individual data members can’t be returned, b) Individual data members can be returned, c) Individual member functions can be returned from another function, d) Individual data members can only be passed by reference, View Answer, Answer: b, Explanation: It is not mandatory to return the whole object. Instead we can return a specific, data member value. But the return type given must match with the data type of the data being, returned., 11. Can we return an array of objects?, a) Yes, always, b) Ye, only if objects are having same values, c) No, because objects contain many other values, d) No, because objects are single entity, View Answer, Answer: a, Explanation: The Object array can be returned from a function. This can be done by putting a, className* as the return type of the function. This makes the return type to accept an array, of objects in return., 12. If an object is passed by reference to a function then it must be returned by reference., a) True, b) False, View Answer, Answer: b, Explanation: It is not compulsory to return the object in the same way as it was passed. If the, object is passed by reference then there is actually no need to return the object. Because the, changes made inside the function will be visible on the original object of caller function also., 13. Which among the following is true?, a) Two objects can point to the same memory location, b) Two objects can never point to the same memory location
Page 270 :
c) Objects not allowed to point at a location already occupied, d) Objects can’t point to any address, View Answer, Answer: a, Explanation: When an object is created and instead of calling a constructor, another object is, assigned to it. Both the objects point to the same memory location. This can be illustrated, with help of return by reference., advertisement, , 14. If an object is being returned by value then __________________________, a) Its member values are made constant, b) Its member values have to be copied individually, c) Its member values are not used, d) Its member values are copied using copy constructor, View Answer, Answer: d, Explanation: When an object is returned by value, it will be returned to another object or will, be directly used. Still in all the conditions the copy constructor will be used to copy all the, values from the temporary object that gets created., 15. Why temporary object is not created in return by reference?, a) Because compiler can’t create temporary objects, b) Because the temporary object is created within the function, c) Because return by reference just make the objects points to values memory location, d) Because return by reference just make the object point to null, View Answer, Answer: c, Explanation: A reference to the memory location where the returned object is stored is made., This allows the new object which takes the return value, point to the memory location and, hence access the same values., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Passing Object to, Functions, » Next - Object Oriented Programming Questions and Answers – Assigning Objects, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Passing Object to Functions
Page 271 :
Object Oriented Programming Questions and Answers – Assigning Objects, advertisement, advertisement, , Recommended Posts:, 1. Python Programming Examples, 2. Java Programming Examples on Multithreading, 3. C# Programming Examples on Files, 4. C Programming Examples on Bitwise Operations, 5. C Programming Examples on Stacks & Queues, 6. Java Programming Examples on Utility Classes, 7. Ruby Programming Questions and Answers, 8. Java Programming Examples on Computational Geometry Problems & Algorithms, 9. Java Programming Examples on String Handling, 10. Java Programming Examples on Data-Structures, 11. Java Programming Examples, 12. C++ Programming Examples on Computational Geometry Problems & Algorithms, 13. C# Programming Examples on Functions, 14. C Programming Examples on Computational Geometry Problems & Algorithms, 15. C# Programming Examples on LINQ, 16. Java Programming Examples on File Handling, 17. Java Programming Examples on Java.Lang, 18. Java Programming Examples on Collections, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Assigning Objects, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Assigning Objects―., 1. When value of an object is assigned to another object ________________, a) It becomes invalid statement, b) Its values gets copied into another object, c) Its values gets address of the existing values, d) The compiler doesn’t execute that statement, View Answer, Answer: b, Explanation: The values get copied to another object. No address is assigned to the object, values. This is uses copy constructor to copy the values., advertisement
Page 272 :
2. If an object is created and another object is assigned to it, then ________________, a) Copy constructor is called to copy the values, b) Object is copied directly to the object, c) Reference to another object is created, d) The new object is initialized to null values, View Answer, Answer: c, Explanation: The new object created, refers to the same address of the previously created, object. Now whenever new object changes any data member value, it will affect the, previously existing object., 3. How the argument passed to a function get initialized?, a) Assigned using copy constructor at time of passing, b) Copied directly, c) Uses addresses always, d) Doesn’t get initialized, View Answer, Answer: a, Explanation: The arguments get initialized using the copy constructor. There is a need of, assigning the value of all the members of an object to the local object of the function., 4. Predict the output of the program., class A, {, public int i;, };, void main(), {, A x;, A y=x;, x.i=10;, y.i=20;, y.i++;, y.i=20;, cout&l;<tx.i;, }, , a) 10, b) 20, c) 21, d) 0, View Answer, Answer: b, Explanation: The expected output may be 10 because the value of member of object x is, printed. But when object x is assigned to y, y points to the same address where x is stored. So, actually both objects x and y point to the same location and refers to the same object., advertisement
Page 273 :
5. If programmer doesn’t define any copy assignment operator then, ____________________, a) Compiler gives an error, b) Program fails at run time, c) Compiler gives an implicit definition, d) Compiler can’t copy the member values, View Answer, Answer: c, Explanation: While defining a copy constructor, we use reference const parameter, those are, used for the assignment. The assignment operator may or may not be defined by the, programmer, if not, compiler implicitly defines member wise copy assignment operator., 6. Declaring a copy constructor doesn’t suppresses the compiler generated copy, assignment operator., a) True, b) False, View Answer, Answer: a, Explanation: Even if the programmer doesn’t define or even if they define the copy, constructor. The compiler still generates a copy assignment operator. It doesn’t gets, suppressed., 7. In copy constructor definition, if non const values are accepted only ________, a) Only const objects will be accepted, b) Only non – const objects are accepted, c) Only const members will not get copied, d) Compiler generates an error, View Answer, Answer: b, Explanation: Only the non – const objects will be accepted by the compiler. If a const, object is passed, the compiler produces an error. To reduce that, we use const argument in, definition, so that both const and non – const objects are accepted., 8. How many objects can be assigned to a single address?, a) Only 1, b) At most 7, c) At most 3, d) As many as required, View Answer, Answer: d, Explanation: The memory address can be referenced by more than one object. There is no, maximum number defined. Any number of objects can reference to the same address., advertisement, , 9. Use of assignment operator ____________________, a) Changes its use, when used at declaration and in normal assignment
Page 274 :
b) Doesn’t changes its use, whatever the syntax might be, c) Assignment takes place in declaration and assignment syntax, d) Doesn’t work in normal syntax, but only with declaration, View Answer, Answer: a, Explanation: The assignment operator if used at declaration then it uses copy constructor for, the copying of objects. If used in simple assignment syntax then it uses copy assignment, function., 10. If more than one object refer to the same address, any changes made __________, a) Can be made visible to specific objects, b) Will be specific to one object only, c) From any object will be visible in all, d) Doesn’t changes the values of all objects, View Answer, Answer: c, Explanation: At a memory address, only one object can be referenced. All the other objects, which refer to the same memory address make changes for all of the objects referring that, address., 11. How to make more than one object refer to the same object?, a) Initialize it to null, b) Initialize the object with another at declaration, c) Use constructor to create new object, d) Assign the address directly, View Answer, Answer: b, Explanation: The object must get initialized with another object at time of declaration only., We don’t have to create a new object we just have to get name of new object because, there after same address will be referred., 12. We can assign ______________________, a) Value of one reference variable to another, b) Value of any object to another, c) Value of any type to any object, d) Value of non – reference to another reference, View Answer, Answer: a, Explanation: Only the reference value can be assigned to another reference value. This is, because both deal with the address. There is no type mismatch hence we can assign them., 13. Assigning reference to an object _________________, a) Will create another copy of the object, b) Will create two different copies of the object, c) Will not create any other copy of the object
Page 275 :
d) Will not refer to the object, View Answer, Answer: c, Explanation: When an object is assigned with another object. Same memory location is used., There is no other copy of the object created., advertisement, , 14. Which among the following is true?, a) We can use direct assignment for any object, b) We can use direct assignment only for different class objects, c) We must not use direct assignment, d) We can use direct assignment to same class objects, View Answer, Answer: d, Explanation: The direct assignment can be used with the same class objects. There is no, restriction on them. But better if the program have a predefined copy assignment operator., 15. Assigning objects takes place while passing the arguments., a) True, b) False, View Answer, Answer: b, Explanation: The actual assignment doesn’t take place as the object might have got, passed by reference. Also even if not by reference, the copy constructor is called to copy the, values into the new object and not exactly the assignment operator., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Returning Objects, » Next - Object Oriented Programming Questions and Answers – Pointer to Objects, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Returning Objects, Object Oriented Programming Questions and Answers – Pointer to Objects, advertisement, advertisement, , Recommended Posts:
Page 276 :
1. C Programming Examples on Linked List, 2. Java Programming Examples on Multithreading, 3. C# Programming Examples on Networking, 4. C Programming Examples on File Handling, 5. Java Programming Examples, 6. C Tutorials, 7. C Programming Examples on Strings, 8. Java Programming Examples on Data-Structures, 9. C# Programming Examples on Mathematics, 10. Java Programming Examples on File Handling, 11. Java Programming Examples on Collections, 12. Java Programming Examples on Utility Classes, 13. Java Programming Examples on String Handling, 14. C# Programming Examples on Functions, 15. Java Programming Examples on Inheritance, 16. C# Programming Examples on Arrays, 17. Java Programming Examples on Java.Lang, 18. Ruby Programming Questions and Answers, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Pointer to Objects, « Prev, Next », , This set of Object Oriented Programming Assessment Questions and Answers focuses on, “Pointer to Objects―., 1. Which language among the following doesn’t allow pointers?, a) C++, b) Java, c) Pascal, d) C, View Answer, Answer: b, Explanation: The concept of pointers is not supported in Java. The feature is not given in the, language but can be used in some ways explicitly. Though this pointer is supported by java, too., advertisement, , 2. Which is correct syntax for declaring pointer to object?, a) className* objectName;, b) className objectName;, c) *className objectName;
Page 277 :
d) className objectName();, View Answer, Answer: a, Explanation: The syntax must contain * symbol after the className as the type of object., This declares an object pointer. This can store address of any object of the specified class., 3. Which operator should be used to access the members of the class using object pointer?, a) Dot operator, b) Colon to the member, c) Scope resolution operator, d) Arrow operator, View Answer, Answer: d, Explanation: The members can be accessed from the object pointer by using arrow operator., The arrow operator can be used only with the pointer of class type. If simple object is, declared, it must use dot operator to access the members., 4. How does compiler decide the intended object to be used, if more than one object are, used?, a) Using object name, b) Using an integer pointer, c) Using this pointer, d) Using void pointer, View Answer, Answer: c, Explanation: This pointer denotes the object, in which it is being used. If member function is, called with respect to one object then this pointer refers to the same object members. It can be, used when members with same name are involved., 5. If pointer to an object is declared __________, a) It can store any type of address, b) It can store only void addresses, c) It can only store address of integer type, d) It can only store object address of class type specified, View Answer, Answer: d, Explanation: The address of only the specified class type can get their address stored in the, object pointer. The addresses doesn’t differ but they do differ for the amount and type of, memory required for objects of different classes. Hence same class object pointer should be, used., advertisement, , 6. What is the size of an object pointer?, a) Equal to size of any usual pointer, b) Equal to size of sum of all the members of object, c) Equal to size of maximum sized member of object
Page 278 :
d) Equal to size of void, View Answer, Answer: a, Explanation: The size of object pointer is same as that of any usual pointer. This is because, only the address have to be stored. There are no values to be stored in the pointer., 7. A pointer _________________, a) Can point to only one object at a time, b) Can point to more than one objects at a time, c) Can point to only 2 objects at a time, d) Can point to whole class objects at a time, View Answer, Answer: a, Explanation: The object pointer can point to only one object at a time. The pointer will be, able to store only one address at a time. Hence only one object can be referred., 8. Pointer to a base class can be initialized with the address of derived class, because of, _________, a) derived-to-base implicit conversion for pointers, b) base-to-derived implicit conversion for pointers, c) base-to-base implicit conversion for pointers, d) derived-to-derived implicit conversion for pointers, View Answer, Answer: a, Explanation: It is an implicit rule defined in most of the programming languages. It permits, the programmer to declare a pointer to the derived class from a base class pointer. In this way, the programmer doesn’t have to declare object for derived class each time it is required., 9. Can pointers to object access the private members of the class?, a) Yes, always, b) Yes, only if it is only pointer to object, c) No, because objects can be referenced from another objects too, d) No, never, View Answer, Answer: d, Explanation: The pointers to an object can never access the private members of the class, outside the class. The object can indirectly use those private members using member, functions which are public in the class., 10. Is name of an array of objects is also a pointer to object?, a) Yes, always, b) Yes, in few cases, c) No, because it represents more than one object, d) No, never, View Answer
Page 279 :
Answer: a, Explanation: The array name represents a pointer to the object. The name alone can represent, the starting address of the array. But that also represents an array which is in turn stored in a, pointer., advertisement, , 11. Which among the following is true?, a) The pointer to object can hold address only, b) The pointer can hold value of any type, c) The pointer can hold only void reference, d) The pointer can’t hold any value, View Answer, Answer: a, Explanation: The pointer to an object can hold only the addresses. Address of any other, object of same class. This allows the programmer to link more than one objects if required., 12. Which is the correct syntax to call a member function using pointer?, a) pointer->function(), b) pointer.function(), c) pointer::function(), d) pointer:function(), View Answer, Answer: a, Explanation: The pointer should be mentioned followed by the arrow operator. Arrow, operator is applicable only with the pointers. Then the function name should be mentioned, that is to be called., 13. If a pointer to an object is created and the object gets deleted without using the pointer, then __________, a) It becomes void pointer, b) It becomes dangling pointer, c) It becomes null pointer, d) It becomes zero pointer, View Answer, Answer: b, Explanation: When the address pointed by the object pointer gets deleted, the pointer now, points to an invalid address. Hence it becomes a dangling pointer. It can’t be null or void, pointer since it doesn’t point to any specific location., 14. How can the address stored in the pointer be retrieved?, a) Using * symbol, b) Using $ symbol, c) Using & symbol, d) Using @ symbol, View Answer
Page 280 :
Answer: c, Explanation: The & symbol must be used. This should be done such that the object should be, preceded by & symbol and then the address should be stored in another variable. This is done, to get the address where the object is stored., 15. What should be done to prevent changes that may be made to the values pointed by the, pointer?, a) Usual pointer can’t change the values pointed, b) Pointer should be made virtual, c) Pointer should be made anonymous, d) Pointer should be made const, View Answer, Answer: d, Explanation: The pointer should be declared as a const type. This prevents the pointer to, change any value that is being pointed from it. This is a feature that is made to access the, values using pointer but to make sure that pointer doesn’t change those values accidently., advertisement, , 16. References to object are same as pointers of object., a) True, b) False, View Answer, Answer: b, Explanation: The references are made to object when the object is created and initialized with, another object without calling any constructor. But the object pointer must be declared, explicitly using * symbol that will be capable of storing some address. Hence both are, different., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming Assessment Questions, here is, complete set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Assigning Objects, » Next - Object Oriented Programming Questions and Answers – This Pointer, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Assigning Objects, Object Oriented Programming Questions and Answers – This Pointer, advertisement, advertisement, , Recommended Posts:
Page 281 :
1. C# Programming Examples on Networking, 2. C# Programming Examples on Arrays, 3. Java Programming Examples on Data-Structures, 4. Java Programming Examples, 5. C# Programming Examples on Functions, 6. C Tutorials, 7. Java Programming Examples on String Handling, 8. Java Programming Examples on File Handling, 9. Python Programming Examples on Linked Lists, 10. Ruby Programming Questions and Answers, 11. Java Programming Examples on Utility Classes, 12. Java Programming Examples on Classes, 13. C Programming Examples on Arrays, 14. C Programming Examples on Linked List, 15. Java Programming Examples on Collections, 16. Java Programming Examples on Java.Lang, 17. C# Programming Examples on Inheritance, 18. Java Programming Examples on Inheritance, 19. C++ Questions and Answers, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – This Pointer, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “This Pointer―., 1. Which is the pointer which denotes the object calling the member function?, a) Variable pointer, b) This pointer, c) Null pointer, d) Zero pointer, View Answer, Answer: b, Explanation: The pointer which denotes the object calling the member function is known as, this pointer. The this pointer is usually used when there are members in the function with, same name as those of the class members., advertisement, , 2. Which among the following is true?, a) this pointer is passed implicitly when member functions are called, b) this pointer is passed explicitly when member functions are called, c) this pointer is passed with help of pointer member functions are called
Page 282 :
d) this pointer is passed with help of void pointer member functions are called, View Answer, Answer: a, Explanation: When an object calls some member function, it implicitly passes itself as an, argument. This allows the compiler to know which member should be used for the purposes., This also allows to reduce the ambiguity among the variable and data member names., 3. The this pointer is accessible __________________, a) Within all the member functions of the class, b) Only within functions returning void, c) Only within non-static functions, d) Within the member functions with zero arguments, View Answer, Answer: c, Explanation: The this pointer is available only within the non-static member functions of a, class. If the member function is static, it will be common to all the objects and hence a single, object can’t refer to those functions independently., 4. An object’s this pointer _____________________, a) Isn’t part of class, b) Isn’t part of program, c) Isn’t part of compiler, d) Isn’t part of object itself, View Answer, Answer: d, Explanation: The object’s this pointer being called are not part of the object itself. This, can be cross verified by checking that it doesn’t take up any space for the data to be, stored or pointed., 5. The result of sizeof() function __________________, a) Includes space reserved for this pointer, b) Includes space taken up by the address pointer by this pointer, c) Doesn’t include the space taken by this pointer, d) Doesn’t include space for any data member, View Answer, Answer: c, Explanation: The space taken by this pointer is not reflected in by the sizeof() operator. This, is because object’s this pointer is not part of object itself. This is a cross verification for, the concept stating that this pointer doesn’t take any space in the object., advertisement, , 6. Whenever non-static member functions are called _______________, a) Address of the object is passed implicitly as an argument, b) Address of the object is passed explicitly as an argument, c) Address is specified globally so that the address is not used again
Page 283 :
d) Address is specified as return type of the function, View Answer, Answer: a, Explanation: The address is passed implicitly as an argument to the function. This doesn’t, have to be passed explicitly. The address is passed, of the object which is calling the nonstatic member function., 7. Which is the correct interpretation of the member function call from an object,, object.function(parameter);, a) object.function(&this, parameter), b) object(&function,parameter), c) function(&object,¶meter), d) function(&object,parameter), View Answer, Answer: d, Explanation: The function name is specified first and then the parameter lists. The parameter, list is included with the object name along with & symbol. This denotes that the address of, the object is being passed as an argument., 8. The address of the object _________________, a) Can’t be accessed from inside the function, b) Can’t be accessed in the program, c) Is available inside the member function using this pointer, d) Can be accessed using the object name inside the member function, View Answer, Answer: c, Explanation: The address of the object with respect to which the member functions are being, called, are stored in this pointer. This pointer is hence used whenever there are members with, same name as those of the variables inside the function., 9. Which among the following is true?, a) This pointer can be used to guard against any kind of reference, b) This pointer can be used to guard against self-reference, c) This pointer can be used to guard from other pointers, d) This pointer can be used to guard from parameter referencing, View Answer, Answer: b, Explanation: The this pointer can be used to guard itself whenever self-reference is used. This, allows accidental address access. And accidental modification of data., advertisement, , 10. Which syntax doesn’t execute/is false when executed?, a) if(&object != this), b) if(&function !=object), c) this.if(!this)
Page 284 :
d) this.function(!this), View Answer, Answer: a, Explanation: The condition becomes false when executed and hence doesn’t executes., This is the case where this pointer can guard itself from the self-reference. Here if the address, of the object doesn’t match with this pointer that means the object doesn’t refer itself., 11. The this pointers _____________________, a) Are modifiable, b) Can be assigned any value, c) Are made variables, d) Are non-modifiable, View Answer, Answer: d, Explanation: The this pointer is non modifiable. This is because the address of any object, remains constant throughout its life time. Hence the address must not be changed otherwise, wrong members of invalid addresses might get accessed., 12. Earlier implementations of C++ ___________________, a) Never allowed assignment to this pointer, b) Allowed no assignment to this pointer, c) Allowed assignments to this pointer, d) Never allowed assignment to any pointer, View Answer, Answer: c, Explanation: The earlier, most initial versions of C++ used to allow assignments to this, pointers. That used to allow modifications of this pointer. Later that feature got disabled., 13. This pointer can be used directly to ___________, a) To manipulate self-referential data structures, b) To manipulate any reference to pointers to member functions, c) To manipulate class references, d) To manipulate and disable any use of pointers, View Answer, Answer: a, Explanation: This is a feature provided, that can be used directly. The manipulation of selfreferential data structures is just an application of this feature. Other conditions fails as this, pointer doesn’t deal with those things., advertisement, , 14. Which among the following is/are type(s) of this pointer?, a) const, b) volatile, c) const or volatile, d) int, View Answer
Page 285 :
Answer: c, Explanation: The this pointer can be declared const or volatile. This depends on need of, program and type of code. This is just an additional feature., 15. Which is the correct syntax for declaring the type of this in a member function?, a) classType [cv-qualifier-list] *const this;, b) classType const[cv-qualifier-list] *this;, c) [cv-qualifier-list]*const classType this;, d) [cv-qualifier-list] classType *const this;, View Answer, Answer: d, Explanation: The syntax contains the cv-qualifier-list that can be determined from the, member function declaratory that can be either const or volatile or can be made both. Hence, we write it as list. classType denotes the name of class to mention to which class does the, object belong to. And *const this denotes that the this pointer is having a constant value., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Pointer to Objects, » Next - Object Oriented Programming Questions and Answers – Default Arguments, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Pointer to Objects, Object Oriented Programming Questions and Answers – Default Arguments, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples, 2. C# Programming Examples on Strings, 3. C# Programming Examples on Networking, 4. Java Programming Examples on Multithreading, 5. Java Programming Examples on Utility Classes, 6. Java Programming Examples, 7. C Programming Examples on Mathematical Functions, 8. C++ Programming Examples on Data-Structures, 9. R Programming Questions and Answers, 10. C# Programming Examples, 11. Java Programming Examples on Networking, 12. Java Programming Examples on Collections
Page 286 :
13. C Tutorials, 14. C Programming Examples on Stacks & Queues, 15. Java Programming Examples on Inheritance, 16. Python Programming Examples on Linked Lists, 17. Java Programming Examples on Classes, 18. C# Programming Examples on Functions, 19. C Programming Examples on Linked List, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Default Arguments, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Default Arguments―., 1. What are default arguments?, a) Arguments which are not mandatory to be passed, b) Arguments with default value that aren’t mandatory to be passed, c) Arguments which are not passed to functions, d) Arguments which always take same data value, View Answer, Answer: b, Explanation: The arguments which are assigned with some default value. Since some value is, already given, it is not mandatory to pass those arguments. They can be used directly., advertisement, , 2. Which is the correct condition for the default arguments?, a) Those must be declared as last arguments in argument list, b) Those must be declared first in the argument list, c) Those can be defined anywhere in the argument list, d) Those are declared inside the function definition, View Answer, Answer: a, Explanation: The default arguments must be declared at last in the argument list. This is to, ensure that the arguments doesn’t create ambiguity. The normal arguments should be, passed first., 3. If a member function have to be made both zero argument and parameterized constructor,, which among the following can be the best option?, a) Two normal and one default argument, b) At least one default argument, c) Exactly one default argument
Page 287 :
d) Make all the arguments default, View Answer, Answer: d, Explanation: All the arguments must be made default. This will make sure that none of the, arguments are mandatory to be passed. Which in turn means that the function can work, without any argument and can be passed with arguments too., 4. Which among the following function can be called without arguments?, a) void add(int x, int y=0), b) void add(int=0), c) void add(int x=0, int y=0), d) void add(char c), View Answer, Answer: c, Explanation: For the function to be called without arguments, either it must have zero, arguments or it must have all the default arguments. Here the function in option void add(int, x=0, int y=0) have all the default arguments and hence can be called directly with zero, argument., 5. If a function have all the default arguments but still some values are passed to the function, then ______________, a) The function will use the values passed to it, b) The function will use the default values as those are local, c) The function can use any value whichever is higher, d) The function will choose the minimum values, View Answer, Answer: a, Explanation: The function will use the values passed explicitly to it. The default values will, be ignored. The default values are used only in case the values are not passed explicitly to the, function., advertisement, , 6. Which among the following is correct?, a) void test(int x=0, int y, int z=0), b) void test(int x=0, int=0), c) void test(int x, int y=0), d) void test(int x=’c, int y), View Answer, Answer: c, Explanation: The default arguments must be mentioned at last in the argument list. Also, the, type of values assigned must match with the argument type. All the default arguments must, be mentioned at last, none of the normal arguments should come in between the default, arguments list., 7. What function will be called with the independent syntax “test(5,6,7);―?, a) void test(int x, int y)
Page 288 :
b) void test(int x=0, int y, int z), c) int test(int x=0, y=0, z=0), d) void test(int x, int y, int z=0), View Answer, Answer: d, Explanation: There are three arguments that are getting passed to the function test(). Only the, last option have all the default argument at last in the argument list. And the total number of, the arguments is three. The third option is wrong because the return type is int and the syntax, given is independent which means it doesn’t return any value., 8. Which among the following is a wrong call to the function void test(int x, int y=0, int, z=0)?, a) test(5,6,7);, b) test(5);, c) test();, d) test(5,6);, View Answer, Answer: c, Explanation: The function must be passed with at least one argument. There is two default, arguments and one normal argument which must be passed with some value. Hence the third, call to the function is wrong as it doesn’t pass even a single parameter to the function, 9. Default arguments are _________________________, a) Only allowed in the parameter list of the function declaration, b) Only allowed in the return type of the function declaration, c) Only allowed with the class name definition, d) Only allowed with the integer type values, View Answer, Answer: a, Explanation: The default arguments are only allowed in the parameter list of the function, arguments. This rule was not applicable in the beginning versions of c++ but later from c++, 14th version it has been implemented. This is the only way to use default arguments., advertisement, , 10. Which among the following is false for default arguments?, a) Those are not allowed with a declaration of pointer to functions, b) Those are not allowed with the reference to functions, c) Those are not allowed with the typedef declarations, d) Those are allowed with pointer and reference to function declaration, View Answer, Answer: d, Explanation: The statements given are true because that is a feature given to make the, programming more flexible and have some security with accidental changes at same time., The last option is false because it is not a rule defined. It is an opposite statement to the rules, defined for default arguments.
Page 289 :
11. The non-template functions can be added with default arguments to already declared, functions ____________________, a) If and only if the function is declared again in the same scope, b) If and only if the function is declared only once in the same scope, c) If and only if the function is declared in different scope, d) If and only if the function is declared twice in the program, View Answer, Answer: a, Explanation: The non-template functions can also be added with default arguments. This can, be done even if the functions were defined earlier. This is because the call to the function, won’t be affected. The function can still be used in the same way as it was used earlier., 12. The using declaration __________, a) Doesn’t carry over the default values, b) Carries over the known default arguments, c) Carries over only the normal arguments, d) Carries over only few default arguments, View Answer, Answer: b, Explanation: The using-declaration carries over all the known default arguments. This is a, common feature as the usage doesn’t gets affected even if the default arguments are, added. This comes under flexible programming., 13. The names given to the default arguments are only looked up and ________________, and are bound during declaration., a) Checked for availability, b) Checked for random access, c) Checked for accessibility, d) Checked for feasibility, View Answer, Answer: c, Explanation: The names given to the default arguments are bound at time of declaration but, are only checked for accessibility and to get bounded. This is mainly to bind those members, during declaration., advertisement, , 14. The default argument get bound during declaration ________________, a) And are never executed, b) And are executed simultaneously, c) But are executed only if priority is given, d) But are executed during function call, View Answer, Answer: d, Explanation: The default argument are bound at the time of declaration. That is an implicit, functioning. But those are executed only when the function is called. Otherwise, those will, never get executed.
Page 290 :
15. The virtual function overrides ____________, a) Do not acquire base class declaration of default arguments, b) Do acquire base class declaration of default arguments, c) Do not link with the default arguments of base class, d) Do link with the default argument but only of derived classes, View Answer, Answer: a, Explanation: The virtual function overrides do not acquire the base class declaration of, default arguments. Even if a call to the virtual function is made, static type of the object, decides the default arguments to be used., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – This Pointer, » Next - Object Oriented Programming Questions and Answers – Constructors, Overloading, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – This Pointer, Object Oriented Programming Questions and Answers – Constructors Overloading, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples on Linked List, 2. Java Programming Examples, 3. C Programming Examples on Stacks & Queues, 4. Simple C Programs, 5. C Tutorials, 6. C Programming Examples, 7. R Programming Questions and Answers, 8. C++ Programming Examples on Data-Structures, 9. C# Programming Examples on Arrays, 10. C Programming Examples on Arrays, 11. C Programming Examples on Strings, 12. Java Programming Examples on Inheritance, 13. Ruby Programming Questions and Answers, 14. C# Programming Examples on Functions, 15. C Programming Examples on Searching and Sorting, 16. C++ Questions and Answers
Page 291 :
17. C Programming Examples on File Handling, 18. Java Programming Examples on File Handling, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Constructors Overloading, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Constructors Overloading―., 1. Which among the following is true for constructors overloading?, a) Constructors can’t be overloaded, b) Constructors can be overloaded using different signatures, c) Constructors can be overloaded with same signatures, d) Constructors can be overloaded with different return types, View Answer, Answer: b, Explanation: The constructors can be overloaded only if the definitions have different, signatures. Constructors doesn’t have any return type so can’t be overloaded using, return type. If constructors have same signature then it will produce a compile time error., advertisement, , 2. If a constructors should be capable of creating objects without argument and with, arguments, which is a good alternative for this purpose?, a) Use zero argument constructor, b) Use constructor with one parameter, c) Use constructor with all default arguments, d) Use default constructor, View Answer, Answer: c, Explanation: The constructor should use all the default arguments. This will allow the, constructor to be called even if no arguments are passed. And if arguments are passed, those, will be accepted instead of the default values., 3. The Constructors with all the default arguments are similar as default constructors., a) True, b) False, View Answer
Page 292 :
Answer: a, Explanation: The constructors with all the default arguments are similar as the default, constructors. Those can be used instead of the default constructors. So defining the default, constructor is not mandatory., 4. Which among the following is true?, a) The constructors overloading can be done by using different names, b) The constructors overloading can be done by using different return types, c) The constructors can be overloaded by using only one argument, d) The constructors must have the same name as that of class, View Answer, Answer: d, Explanation: The constructors must have the same name as that of the class name. This is, mandatory because only the constructor functions doesn’t have any return type. Also, for, overloading all the functions must have the same name., 5. Which among the following can be used in place of default constructor?, a) constructorName(int x, int y=0), b) constructorName(int x=0, int y=0), c) constructorName(int x=0, int y), d) constructorName(int x, int y), View Answer, Answer: b, Explanation: For a parameterized constructor to be used as a default constructor, it must have, all the default arguments. This makes the constructor to have optional arguments which are, not mandatory to be passed., advertisement, , 6. Can a class have more than one function with all the default arguments?, a) Yes, always, b) Yes, if argument list is different, c) No, because constructors overloading doesn’t depend on argument list, d) No, never, View Answer, Answer: d, Explanation: A single class can never have more than once constructor with all the default, arguments. This is because it will make all those constructors as a default constructor. And, when an object is created with zero arguments then it will create ambiguity., 7. Which is the correct syntax for using default arguments with the constructor?, a) default constructorName(default int x=0), b) constructorName(default int x=0), c) constructorName(int x=0), d) constructorName(), View Answer
Page 293 :
Answer: c, Explanation: The constructors using the default arguments must initialize the arguments in, the argument list. This is to make the constructor use the default value when no arguments, are passed. If no arguments are listed then it is a default constructor., 8. How many parameters must be passed if only the following prototype is given to a, constructor?, Prototype: className(int x, int y, int z=0);, a) 1, b) 2, c) 3, d) Compile time error, View Answer, Answer: b, Explanation: In the prototype given, only 2 arguments are mandatory. Since the third, argument is default argument, so it is not mandatory to pass the argument., 9. If the constructors are overloaded by using the default arguments, which problem may, arise?, a) The constructors might have all the same arguments except the default arguments, b) The constructors might have same return type, c) The constructors might have same number of arguments, d) The constructors can’t be overloaded with respect to default arguments, View Answer, Answer: a, Explanation: The constructors having same arguments except the default arguments can give, rise to errors. If only the mandatory arguments are passed, it will create ambiguity in calling, the correct constructor. Hence the mandatory arguments must be different., advertisement, , 10. Which among the following is true?, a) More than one constructors with all default arguments is allowed, b) More than one constructors with all default arguments can be defined outside the class, c) More than one constructors can be used with same argument list, d) More than one constructors with all default arguments can’t exist in same class, View Answer, Answer: d, Explanation: The constructors must have different argument list. Along that, if all the, arguments are default arguments, there can’t be more than once constructor like that in, the same class as that will create ambiguity while constructors are being called., 11. Which constructor among the following will be called if a call is made like, className(5,’a’);?, a) className(int x=5,char c=’a’);, b) int className(int x, char c, char d);, c) className(int x, char c, int y);
Page 294 :
d) char className(char c,int x);, View Answer, Answer: a, Explanation: The syntax given is passing two parameters to the constructor call. One value is, of integer type and another of character type. Hence the constructor with arguments of int and, char type should be called. There is only one option that first accepts integer value and then a, character value. Hence that constructor will be called., 12. Which constructor definition will produce a compile time error?, a) className(int x=0);, b) className(char c);, c) className(int x=0,char c);, d) className(char c,int x=0);, View Answer, Answer: c, Explanation: The default arguments, just like with member functions, must be listed at last in, the argument list. Hence this will produce a compile time error. The compiler doesn’t, allow the definition to be executed., 13. If there is a constructor with all the default arguments and arguments are not passed then, _________________, a) The default values given will not be used, b) Then all the null values will be used, c) Then all the default values given will be used, d) Then compiler will produce an error, View Answer, Answer: c, Explanation: The constructors will use the default values listed for use. The null values are, not used because those are not specified. Though if it was compiler provided default, constructor, then it would have initialized the members to null or zero values., advertisement, , 14. Which is the correct statement for default constructors?, a) The constructors with all the default arguments, b) The constructors with all the null and zero values, c) The constructors which can’t be defined by programmer, d) The constructors with zero arguments, View Answer, Answer: d, Explanation: The closest answer to the question is that a default constructor is a constructor, with zero arguments. But this is not the actual case. Actually the constructors provided by the, compiler are default constructors. And the constructors with zero arguments defined by the, programmer are zero argument constructors., 15. Which is a good alternative instead of having one zero argument constructor and one, single argument constructor with default argument?
Page 295 :
a) No constructor defined, b) One default value constructor, c) Defining the default constructor, d) Using one constructor with two arguments, View Answer, Answer: b, Explanation: The constructor with one default argument can be the best alternative. This is, because the constructor with one default value will do the work for both the default, constructor and one argument constructor., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Default Arguments, » Next - Object Oriented Programming Questions and Answers – Upcasting, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Default Arguments, Object Oriented Programming Questions and Answers – Upcasting, advertisement, advertisement, , Recommended Posts:, 1. C++ Programming Examples on Data-Structures, 2. C Programming Examples on Arrays, 3. Java Programming Examples on Utility Classes, 4. C# Basic Programming Examples, 5. C# Questions and Answers, 6. Java Programming Examples on Collections, 7. C Programming Examples on File Handling, 8. Java Programming Examples, 9. C# Programming Examples on Arrays, 10. C# Programming Examples on Delegates, 11. Java Programming Examples on Networking, 12. C++ Questions and Answers, 13. C# Programming Examples on Mathematics, 14. Java Programming Examples on Multithreading, 15. Java Programming Examples on Java.Lang, 16. Java Programming Examples on Exception Handling, 17. Java Programming Examples on File Handling, 18. Java Programming Examples on Inheritance
Page 296 :
19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Upcasting, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Upcasting―., 1. What is upcasting?, a) Casting subtype to supertype, b) Casting super type to subtype, c) Casting subtype to super type and vice versa, d) Casting anytype to any other type, View Answer, Answer: a, Explanation: The upcasting concept includes only the casting of subtypes to the super types., This casting is generally done implicitly. Smaller size types can fit into larger size types, implicitly., advertisement, , 2. Which among the following is true for upcasting in inheritance?, a) Downward to the inheritance tree, b) Upward to the inheritance tree, c) Either upward or downward, d) Doesn’t apply on inheritance, View Answer, Answer: b, Explanation: The upcasting concept in inheritance is always applied upward the inheritance, tree. The derived class objects can be type casted to any of its parent class type. Since is a, relationship applies in general inheritance., 3. Which among the following is safe?, a) Upcasting, b) Downcasting, c) Both upcasting and downcasting, d) If upcasting is safe then downcasting is not, and vice versa, View Answer, Answer: a, Explanation: The upcasting is always safe since the derived type or the smaller type is
Page 297 :
converted into the base type or the larger size. This results in allocating a smaller size data, into bigger type data. No data is lost in casting, hence safe., 4. Which among the following is the best situation to use upcasting?, a) For general code dealing with only subtype, b) For general code dealing with only supertype, c) For general code dealing with both the supertype and subtype, d) For writing a rigid code with respect to subtype, View Answer, Answer: b, Explanation: When a general code has to be written where we use only the supertype object, or the data of bigger size, then upcasting would be the best option. Since the whole code will, require only the supertype name references., 5. Which property is shown most when upcasting is used?, a) Code reusability, b) Code efficiency, c) Complex code simple syntax, d) Encapsulation, View Answer, Answer: c, Explanation: The code written using upcasting mostly shows complex code in simpler syntax, features. This is because the upcasting concept can be applied as polymorphism and to group, the similar type of objects., advertisement, , 6. Upcasting and downcasting objects are the same as casting primitive types., a) True, b) False, View Answer, Answer: b, Explanation: It is a bit confusing concept since both casting concepts are different. Primitive, casting depends on the type and size of data being typecast. Whereas in objects casting, the, classes and inheritance order plays a big role., 7. Which casting among the following is allowed for the code given below?, class A, {, public :int a;, }, class B:public A, {, int b;, }, main(), {, B b=new A(); //casting 1, A a=new B(); //casting 2
Page 298 :
}, , a) Casting 1, b) Casting 2, c) casting 1 and casting 2, d) casting 1 nor casting 2, View Answer, Answer: b, Explanation: The casting 2 is correct. The objects casting must be done from derived class, object to a parent class object. That is, the object of the superclass can be made an object of, subclass only. Vice versa is not possible., 8. If multiple inheritance is implemented, which upcasting will be correct?, a) Upcast to first base class listed in inheritance, b) Upcast to send base class listed in inheritance, c) Upcast to any base class, d) Upcast is not possible, View Answer, Answer: c, Explanation: The upcasting of derived class object is possible to any base class. This is, because the base class object can represent any of its derived classes using upcasting., advertisement, , 9. If class C inherits class B and class B inherits class A ________________, a) Class C object can be upcasted to object of class B only, b) Class C object can be upcasted to object of class A only, c) Class C object can be upcasted to object of either class A or B, d) Class C object can’t be upcasted, View Answer, Answer: c, Explanation: Both class A and B are parent classes of class C. Class C object hence can be, upcasted to any of those class objects. It is not compulsory to upcast to nearest parent., 10. Upcasting is _____________________ without an explicit type cast., a) Always allowed for public inheritance, b) Always allowed for protected inheritance, c) Always allowed for private inheritance, d) Not allowed, View Answer, Answer: a, Explanation: The public inheritance shows the most flexible is-a relationship. Hence explicit, type casting is not required. Implicit type casting is done by the compiler., 11. Which concept is needed because of implicit type casting use?, a) Static binding, b) Dynamic binding
Page 299 :
c) Compile time binding, d) Source code binding, View Answer, Answer: b, Explanation: Since the implicit type casting allows casting of a base class pointer to refer to, its derived class object or even base class object. We need dynamic type casting so that the, references can be resolved during execution of program., 12. When are the pointer types known for upcasting the objects?, a) Compile time, b) Runtime, c) Source code build time, d) Doesn’t apply to pointer types, View Answer, Answer: a, Explanation: The pointer or reference types are known at compile time for the upcasting of an, object. This is because the addresses must be known for casting the derived class to base, class object., 13. When are the object type known for upcasting the objects?, a) Compile time, b) Runtime, c) Source code build time, d) Doesn’t apply to objects directly, View Answer, Answer: b, Explanation: The upcasting with objects directly requires runtime resolving. The objects are, fixed and address are allocated at compile time. But the execution of a program requires, runtime knowledge of object types, for implicit type cast., advertisement, , 14. If two classes are defined “Parent― and “Child― then which is the correct type, upcast syntax in C++?, a) Parent *p=child;, b) Parent *p=*child;, c) Parent *p=&child;, d) Parent *p=Child();, View Answer, Answer: c, Explanation: The syntax must contain the base class name first. So that the parent class object, pointer can be declared. Then the object is assigned with the derived class object with &, symbol. & symbol is added to get the address of the derived class object., 15. Which among the following is true?, a) Upcasting is possible only for single level inheritance, b) Upcasting is possible only for multilevel inheritance
Page 300 :
c) Upcasting is possible only for multiple inheritance, d) Upcasting is possible for any type of inheritance, View Answer, Answer: d, Explanation: The type of inheritance doesn’t matter with the upcasting concept., Upcasting applies to all types of inheritance. Any derived class object can be upcasted to any, of its base class object., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Constructors, Overloading, » Next - Object Oriented Programming Questions and Answers – Downcasting, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Constructors Overloading, Object Oriented Programming Questions and Answers – Downcasting, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Networking, 2. C# Programming Examples on LINQ, 3. C# Programming Examples on Events, 4. Java Programming Examples on Data-Structures, 5. C# Programming Examples on Interfaces, 6. Java Programming Examples on Utility Classes, 7. C++ Questions and Answers, 8. Java Programming Examples on Networking, 9. Java Programming Examples on Multithreading, 10. C# Programming Examples on Functions, 11. C# Programming Examples, 12. Java Programming Examples on Java.Lang, 13. Java Programming Examples on Collections, 14. Ruby Programming Questions and Answers, 15. Java Programming Examples on File Handling, 16. Java Programming Examples on Classes, 17. Java Programming Examples, 18. Java Programming Examples on Inheritance, 19. C# Programming Examples on Inheritance
Page 301 :
20. Object Oriented Programming Questions and Answers – OOPs Features, advertisement, , Object Oriented Programming Questions, and Answers – Downcasting, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Downcasting―., 1. What is downcasting?, a) Casting subtype to supertype, b) Casting supertype to subtype, c) Casting subtype to supertype and vice versa, d) Casting anytype to any other type, View Answer, Answer: b, Explanation: The downcasting concept includes only the casting of supertypes to the sub, types. This casting is generally done explicitly. Larger size types are made to fit into small, size types explicitly., advertisement, , 2. Which among the following is a mandatory condition for downcasting?, a) It must not be done explicitly, b) It must be done implicitly, c) It must be done explicitly, d) It can’t be done explicitly, View Answer, Answer: c, Explanation: The downcasting of any object must be done explicitly. This is because the, compilers don’t support the implicit conversion of a supertype to subtype., 3. Downcasting is _______________________, a) Always safe, b) Never safe, c) Safe sometimes, d) Safe, depending on code, View Answer, Answer: b, Explanation: The downcasting concept is made for exception cases. When there is a need to, represent an entity in the form which is not suitable for it. Representing a base type in derived, type is not right but can be done for special cases.
Page 302 :
4. Downcasting ____________________, a) Can result in unexpected results, b) Can’t result in unexpected result, c) Can result only in out of memory error, d) Can’t result in any error, View Answer, Answer: a, Explanation: The result of downcasting can be unexpected. This is because downcasting is, done on the objects into the objects which doesn’t contain any information of data in, lateral object., 5. What should be used for safe downcast?, a) Static cast, b) Dynamic cast, c) Manual cast, d) Implicit cast, View Answer, Answer: b, Explanation: The dynamic cast can be done using the operator dynamic_cast. This converts, one type to another type in a safe way., advertisement, , 6. What does dynamic_cast return after successful type casting?, a) Address of object which is converted, b) Address of object that is used for conversion, c) Address of object that is mentioned in the syntax, d) Doesn’t return any address, View Answer, Answer: a, Explanation: The address of the object which is converted is returned by the dynamic_cast, operator. This is done to safely convert the subtype to supertype. This ensures the proper, assignment and conversion from one type to another., 7. If dynamic_cast fails, which value is returned?, a) void, b) null, c) void pointer, d) null pointer, View Answer, Answer: d, Explanation: The null pointer is returned by the dynamic_cast, if it fails. The conversion, sometimes fails because of too complex type conversion. The conversion may also fail due to, memory or some related issues., 8. Which is the proper syntax of dynamic_cast?, a) dynamic_cast(object)
Page 303 :
b) dynamic_cast new (object), c) dynamic_cast(object), d) dynamic_cast(object), View Answer, Answer: c, Explanation: The dynamic_cast is the name of the operator, which is followed by the new, type in which the object have to be converted. Then the object name is given. This object, name is then used after the type conversion., 9. Which is the exception handler for the exceptions of downcasting?, a) CastException, b) ClassCastingExeption, c) ClassCasting, d) ClassCastException, View Answer, Answer: d, Explanation: The exception handler for the exceptions produced during the downcasting, exception. This handler can be called during runtime to handle any exception thrown., advertisement, , 10. How to prevent the ClassCastExceptions?, a) By using instanceof, b) By using is-a check, c) By using arrow operator with check function, d) By checking type of conversion, View Answer, Answer: a, Explanation: The instanceof operator can be used to check the compatibility of the, conversion. This has to be done to check whether the casting would be safe or not., 11. Java supports direct downcasting., a) True, b) False, View Answer, Answer: b, Explanation: The downcasting is not possible in java directly. This has to be done explicitly., The downcasting is not safe but can be checked for safe casting using instanceof function., 12. Which way the downcasting is possible with respect to inheritance?, a) Upward the inheritance order, b) Downward the inheritance order, c) Either upward or downward the inheritance order, d) Order of inheritance doesn’t matter, View Answer
Page 304 :
Answer: b, Explanation: The downcasting is always downward the inheritance order. Since the base class, object have to be casted into derived class type. This is a basic definition of downcasting., 13. What happens when downcasting is done but not explicitly defined in syntax?, a) Compile time error, b) Runtime error, c) Code write time error, d) Conversion error, View Answer, Answer: a, Explanation: The implicit downcasting is not possible. If tried, the compiler produces an, error. Since the compiler doesn’t allow coasting to a type that is not compatible., advertisement, , 14. When is the downcasting used?, a) To separate inherited class from base class, b) To write a more complex code, c) To compare two objects, d) To disable one class in inheritance, View Answer, Answer: c, Explanation: The downcasting can be used whenever there is a need to compare one object to, another. Equals() function can be used to compare whether the objects were of same age. We, can use getClass() function too., 15. Why is downcasting possible in any language?, a) Because inheritance follows has-a relationship, b) Because inheritance follows is-a relationship, c) Because inheritance doesn’t follow any relationship, d) Because inheritance is not involved in casting, View Answer, Answer: b, Explanation: The downcasting is possible because the classes in inheritance follow is-a, relationship. Hence the derived class is a base class. Which in turn make the downcasting, possible., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Page 305 :
Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Upcasting, » Next - Object Oriented Programming Questions and Answers – New Operator, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Upcasting, Object Oriented Programming Questions and Answers – New Operator, advertisement, advertisement, , Recommended Posts:, 1. C# Programming Examples on Strings, 2. Java Programming Examples on Mathematical Functions, 3. Java Programming Examples on String Handling, 4. C Programming Examples on File Handling, 5. C++ Questions and Answers, 6. C Programming Examples on Bitwise Operations, 7. C# Programming Examples on Arrays, 8. C# Basic Programming Examples, 9. C# Programming Examples on Conversions, 10. C# Programming Examples on Functions, 11. Java Programming Examples on Collections, 12. Java Programming Examples on Java.Lang, 13. Java Programming Examples on Classes, 14. C# Programming Examples, 15. Java Programming Examples on File Handling, 16. Ruby Programming Questions and Answers, 17. Java Programming Examples, 18. Java Programming Examples on Inheritance, 19. C# Programming Examples on Inheritance, 20. Object Oriented Programming Questions and Answers – Hybrid Inheritance, advertisement, , Object Oriented Programming Questions, and Answers – New Operator, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “New Operator―., 1. What is the new operator?, a) Allocates memory for an object or array, b) Allocates memory for an object or array and returns a particular pointer, c) Used as return type when an object is created, d) Used to declare any new thing in a program, View Answer
Page 306 :
Answer: b, Explanation: The new keyword is used to allocate memory of an object or array. The new, object or array can be of any type. Then it returns a suitable non zero pointer to the object., advertisement, , 2. Microsoft C++ Components extensions support new keyword to _____________, a) Modify a vtable, b) Replace a vtable slot entry, c) Add new vtable slot entries, d) Rearrange vtable slot entries, View Answer, Answer: c, Explanation: The new keyword is used for adding new vtable slot entries. This is an, additional feature in Microsoft C++. It can use predefined class object for this work., 3. What happens when new fails?, a) Returns zero always, b) Throws an exception always, c) Either throws an exception or returns zero, d) Terminates the program, View Answer, Answer: c, Explanation: While creating new objects, the new operator may fail because of memory, errors or due to permissions. At that moment the new operator returns zero or it may throw an, exception. The exception can be handled as usual., 4. If new throws an error, which function can be called to write a custom exception handler?, a) _set_handler, b) _new_handler, c) _handler_setter, d) _set_new_handler, View Answer, Answer: d, Explanation: If the default exception handler has to be replaced by a user defined handler, we, can call _set_new_handler run-time library function with the function name as an argument., This lets the programmer to give a custom definition for handling new operator failure., 5. In C++, if new operator is used, when is the constructor called?, a) Before the allocation of memory, b) After the allocation of memory, c) Constructor is called to allocate memory, d) Depends on code, View Answer, Answer: b, Explanation: The constructor function is called after the allocation of memory. In C++ the
Page 307 :
feature works in a bit different way. The memory for all the data members is allocated first, and then the constructor function is called to finalize the memory allocated., advertisement, , 6. Which among the following is correct syntax to declare a 2D array using new operator?, a) char (*pchar)[10] = new char[][10];, b) char (pchar) = new char[][10];, c) char (*char) = new char[10][];, d) char (*char)[][10]= new char;, View Answer, Answer: a, Explanation: The new operator usage to declare a 2D array requires a pointer and size of, array to be declared. Data type and then the pointer with size of array. The left index can be, left blank or any variable can be assigned to it., 7. For declaring data by using new operator ____________________, a) Type name can’t contain const, b) Type name can’t contain volatile, c) Type name can’t contain class declarations, d) Type name can’t contain const, volatile, class declaration or enumerations, View Answer, Answer: d, Explanation: The declaration of any data where we use new operator, any of the mentioned, types are not allowed. This is because the new operator allocated memory based on the type, of data which can be allocated dynamically., 8. The new operator _____________, a) Can allocate reference types too, b) Doesn’t allocate reference types, c) Can allocate reference to objects, d) Doesn’t allocate any data, View Answer, Answer: b, Explanation: The new operator doesn’t allocate reference types. This is because the, reference types are not objects. The new operator is used to allocate memory to the direct, objects., 9. Which among the following is true?, a) New operator can’t allocate functions but pointer to functions can be allocated, b) New operator can allocate functions as well as pointer to functions, c) New operator can allocate any type of functions, d) New operator is not applicable with functions allocation, View Answer, Answer: a, Explanation: The new operator can’t allocate functions but can allocate pointer to the
Page 308 :
functions. This is a security feature as well as to reduce the ambiguity in code. The new, keyword is not given functionality to directly allocate any function., advertisement, , 10. Which among the following is added in grammar of new operator?, a) Finalize, b) Arg, c) Initializer, d) Allocator, View Answer, Answer: c, Explanation: The new operator grammar is added with an initializer field. This can be used to, initialize an object with a user defined constructor. Hence can allocate memory as intended, by the programmer., 11. Initializers __________________, a) Are used for specifying arrays, b) Are used to defined multidimensional arrays, c) Can’t be specified for arrays, d) Can’t be specified for any data, View Answer, Answer: c, Explanation: The initializers can’t be specified for arrays. The initializers can create, arrays of object if and only if the class has a default constructor. That is a zero argument, constructor so that it can be called without any argument., 12. The objects allocated using new operator ________________, a) Are destroyed when they go out of scope, b) Are not destroyed even if they go out of scope, c) Are destroyed anytime, d) Are not destroyed throughout the program execution, View Answer, Answer: b, Explanation: It is not necessary that the objects get destroyed when they go out of scope if, allocated by using new operator. This is because new operator returns a pointer to object that, it had allocated. A suitable pointer with proper scope should be defined by the programmer, explicitly., 13. The new operator _________________, a) Invokes function operator new, b) Doesn’t invoke function operator new, c) Invokes function operator only if required, d) Can’t invoke function operator new implicitly, View Answer
Page 309 :
Answer: a, Explanation: The new operator invokes function operator new. This is done to allocate the, storage to an object. ::operator new is called for storage allocation implicitly., advertisement, , 14. If a new operator is defined for a class and still global new operator have to be used,, which operator should be used with the keyword new?, a) Colon, b) Arrow, c) Dot, d) Scope resolution, View Answer, Answer: d, Explanation: As usual, scope resolution operator is used to get the scope of parent or the, global entities. Hence we can use scope resolution operator with the new operator to call the, global new operator even if new operator is defined for the class explicitly., 15. How does compiler convert “::operator new― implicitly?, a) ::operator new( sizeof( type ) ), b) ::operator new( sizeof( ) ), c) new operator :: type sizeof( type ), d) new sizeof( type ) operator, View Answer, Answer: a, Explanation: The compiler implicitly converts the syntax so that the instruction can be, understood by the processor and proper machine code can be generated. The conversion is, done implicitly and no explicit syntax is required., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Downcasting, » Next - Object Oriented Programming Questions and Answers – Delete Operator, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Downcasting, Object Oriented Programming Questions and Answers – Delete Operator, advertisement, advertisement, , Recommended Posts:
Page 310 :
1. Java Programming Examples on Exception Handling, 2. Java Programming Examples on Data-Structures, 3. C# Programming Examples on Files, 4. C Programming Examples on Linked List, 5. C Programming Examples on Searching and Sorting, 6. C# Programming Examples on Mathematics, 7. Java Programming Examples on Arrays, 8. C# Programming Examples on Delegates, 9. C Programming Examples on Bitwise Operations, 10. Java Programming Examples on Inheritance, 11. Java Programming Examples on Collections, 12. C Programming Examples on Arrays, 13. Java Programming Examples, 14. C# Programming Examples on Functions, 15. C Programming Examples on Stacks & Queues, 16. C Tutorials, 17. C# Programming Examples on Arrays, 18. Java Programming Examples on Java.Lang, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Delete Operator, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Delete Operator―., 1. What is a delete operator?, a) Deallocates a block of memory, b) Deallocates whole program memory, c) Deallocates only primitive data memory, d) Deallocates all the data reserved for a class, View Answer, Answer: a, Explanation: The delete operator is the reverse process of a new operator. It deallocates all, the memory allocated for an object. The object can be of any type. The delete operator, completely destroys an object so that the resources can be used for other purposes., advertisement, , 2. If an object is allocated using new operator ____________, a) It should be deleted using delete operator, b) It can’t be deleted using delete operator, c) It may or may not be deleted using delete operator
Page 311 :
d) The delete operator is not applicable, View Answer, Answer: a, Explanation: The new operator allocates an object in memory and hence the memory, allocation is bit different from usual allocation of an object. The delete operator can be used, to delete the memory allocated for an object., 3. Does delete return any value?, a) Yes, positive value, b) Yes, negative value, c) Yes, zero value, d) No, View Answer, Answer: d, Explanation: The delete operator doesn’t return any value. Its function is to delete the, memory allocated for an object. This is done in reverse way as that new operator works., 4. Which type of value has resulted from the delete operator?, a) void, b) void pointer, c) null pointer, d) null, View Answer, Answer: a, Explanation: The result of the delete operator is void. The values returned is of no use to the, program or any other system function hence the return type is not defined for the delete, operator., 5. If delete is used to delete an object which was not allocated using new _______________, a) Then out of memory error arises, b) Then unreachable code error arises, c) Then unpredictable errors may arise, d) Then undefined variable error arises, View Answer, Answer: c, Explanation: When the delete operator is used with the objects that were not allocated using, new operator then unpredictable errors may arise. This is because the delete can’t, perform the required actions on the type of memory allocated for the object., advertisement, , 6. Delete operator _________________, a) Can be used on pointers with null value, b) Can be used on pointers with void value, c) Can be used on pointer with value 0, d) Can be used on pointer with any value, View Answer
Page 312 :
Answer: c, Explanation: The delete operator can be used on pointers with the value 0. This actually, means that when new operator fails and return value 0 then deleting the result of failed new, remains harmless. Hence the deletion is possible., 7. When delete operator is used ___________________ (If object has a destructor), a) Object destructor is called after deallocation, b) Object destructor is called before deallocation, c) Object destructor is not used, d) Object destructor can be called anytime during destruction, View Answer, Answer: b, Explanation: The destructor is called before the memory is deallocated for any object. The, destructor call initiates the destruction process and the deallocation of memory takes place., 8. If delete is applied to an object whose l-value is modifiable, then _______________ after, the object is deleted., a) Its value is defined as null, b) Its value is defined as void, c) Its value is defined as 0, d) Its value is undefined, View Answer, Answer: d, Explanation: After performing delete operation on an object whole l-value is modifiable, its, values becomes undefined. This is done so as to denote that the memory space is available to, be used for other purposes., 9. How many variants of delete operator are available?, a) Only 1, b) Only 2, c) Only 3, d) Only 4, View Answer, Answer: b, Explanation: There are two variants of delete operator. One is for object deletion. Other is for, deletion of object array., advertisement, , 10. Which is the correct syntax to delete a single object?, a) delete *objectName;, b) objectName delete;, c) delete objectName;, d) objectName *delete;, View Answer
Page 313 :
Answer: c, Explanation: The object to be deleted is mentioned after the keyword delete. This deletes the, object from memory and free up the memory that was acquired by the object., 11. Which is the correct syntax to delete an array of objects?, a) delete [] objectName;, b) delete * objectName;, c) objectName[] delete;, d) delete objectName[];, View Answer, Answer: a, Explanation: The object array that has to be deleted is mentioned after the keyword delete., But after delete, empty square brackets have to be given to denote that the deletion have to be, done on array of objects., 12. Which cases among the following produces the undefined result?, a) delete [] on an independent object, b) delete on an object array, c) delete [] on an object and delete on object array, d) Undefined result is never produced, View Answer, Answer: c, Explanation: The undefined result is always produced when we try to use delete [] with a, single object. Because the type of deletion mismatches. Same in case where we try to apply, delete to an object array., 13. The delete operator __________________, a) Invokes function operator delete, b) Invokes function defined by user to delete, c) Invokes function defined in global scope to delete object, d) Doesn’t invoke any function, View Answer, Answer: a, Explanation: The delete operator invokes the function operator delete. This function in turn, performs all the delete operations on the mentioned object. This is ensures safe deletion., advertisement, , 14. For objects that are not of class type ______________, a) Global delete operator is invoked, b) Local delete operator is invoked, c) Global user defined function is invoked, d) Local function to delete object is called, View Answer, Answer: a, Explanation: The global delete operator is called to delete the objects that are not of class
Page 314 :
type. Class type includes class, union or struct. All objects of these types can be deleted using, the global delete operator., 15. The delete operator __________________________, a) Can be defined for each class, b) Can’t be defined for each class, c) Can be defined globally only, d) Can’t be defined in a program explicitly, View Answer, Answer: a, Explanation: The delete operator can be defined for each class explicitly. If there is a class for, which delete is not defined then the global delete operator is used. The definition of delete, operator for each class is not necessary., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – New Operator, » Next - Object Oriented Programming Questions and Answers – Automatic Variable, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – New Operator, Object Oriented Programming Questions and Answers – Automatic Variable, advertisement, advertisement, , Recommended Posts:, 1. Ruby Programming Questions and Answers, 2. C Programming Examples on Searching and Sorting, 3. C Programming Examples on Bitwise Operations, 4. Java Programming Examples on Exception Handling, 5. Python Programming Examples on Stacks & Queues, 6. Java Programming Examples on File Handling, 7. C# Programming Examples on LINQ, 8. C Programming Examples on Arrays, 9. C# Programming Examples on Functions, 10. Java Programming Examples, 11. Java Programming Examples on Data-Structures, 12. Java Programming Examples on String Handling, 13. Java Programming Examples on Arrays, 14. Java Programming Examples on Utility Classes
Page 315 :
15. Java Programming Examples on Collections, 16. C Programming Examples on Stacks & Queues, 17. C# Programming Examples on Arrays, 18. Java Programming Examples on Classes, 19. Java Programming Examples on Java.Lang, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Automatic Variable, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Automatic Variable―., 1. What are automatic variables?, a) Global variables, b) Implicit/temporary variables, c) Local variables, d) System variables, View Answer, Answer: c, Explanation: The local variables are also known as automatic variables. The variables in any, local scope that are created and destroyed as the program executes its scope., advertisement, , 2. The memory for automatic variables ___________________, a) Have to be allocated and deallocated explicitly, b) Are allocated and deallocated automatically, c) Is never actually allocated, d) Are never safe, View Answer, Answer: b, Explanation: The memory is allocated and deallocated automatically for the automatic, variables. As soon as the variable comes in scope, the memory is allocated. The variables are, destroyed as soon as those go out of scope., 3. Scope of an automatic variable _______________, a) Is actually the whole program, b) Is actually never fixed, c) Is always equal to the whole program execution, d) Is actually function or block in which it is defined, View Answer
Page 316 :
Answer: d, Explanation: The automatic variables scope is limited only within the block or the function, where those are defined. This is the property of all the automatic variables., 4. Which among the following is true for automatic variables in general?, a) Automatic variables are invisible to called function, b) Automatic variables are always visible to the called function, c) Automatic variables can’t interact with the called function, d) Automatic variables can’t be variable, View Answer, Answer: a, Explanation: The automatic variables are hidden from the called function. Even if passed by, reference or address, the address of the variable is used and not the actual variable of calling, function. Automatic variables can be const or variable., 5. If an automatic variable is created and then a function is called then ________________, a) The automatic variable created gets destroyed, b) The automatic variable doesn’t get destroyed, c) The automatic variable may or may not get destroyed, d) The automatic variable can’t be used in this case, View Answer, Answer: b, Explanation: The automatic variables are saved till the called function gets executed. This is, done so as to ensure that the program can continue its execution after the called function is, returned. The automatic variables gets destroyed only if those go out of scope., advertisement, , 6. Where are the automatic variables stored if another function is called in between the, execution of the program?, a) Heap, b) Queue, c) Stack, d) Temp variable, View Answer, Answer: c, Explanation: All the automatic variables are stored in a new stack entry as soon as their scope, is created. If another function is called, the present data is saved in stack and new entry in, stack is made for the called function. When the function returns, the automatic variables are, used again from where those were left., 7. The static variables of a function ________________, a) Are also automatic variables, b) Are not automatic variables, c) Are made automatic by default, d) Can be made automatic explicitly, View Answer
Page 317 :
Answer: b, Explanation: The static members can’t be automatic. This is because the automatic, variables are created and destroyed with each call to a specific function. But the static, members remain throughout the execution of program once created., 8. All variables declared within a block ____________________, a) Are not always automatic, b) Can be made non-automatic, c) Are static by default, d) Are automatic by default, View Answer, Answer: d, Explanation: The variables declared inside a block, are make automatic by default. This is to, ensure that the variables get destroyed when not required. The variables remain live only till, those are required, the life is dependent on the scope of a variable., 9. What values does uninitialized automatic variables contain?, a) Null value, b) Void value, c) Undefined/Garbage, d) Zero value, View Answer, Answer: c, Explanation: The automatic variable which are not initialized, contain garbage value. If we, just declare a variable and try to print its value, the result is some unknown value. The value, is garbage as that was not expected value., advertisement, , 10. Constructor of automatic variables is called ____________________, a) When execution reaches the place of declaration of automatic variables, b) When the program is compiled, c) When the execution is just started, d) Just before the execution of the program, View Answer, Answer: a, Explanation: Only when the execution reaches the place where the automatic variable was, declared, the constructor is called. This is to ensure that the memory is not allocated if not, needed. The memory is allocated and then destroyed as soon as it goes out of scope., 11. Does java contain auto or register keywords?, a) Yes, for declaring every type of variable, b) Yes, only to declare cache registers, c) No, because java doesn’t support automatic variables, d) No, java supports local variable concept, View Answer
Page 318 :
Answer: d, Explanation: The auto and register keywords are not supported in java. Though the same is, allowed in java without specifying any of those keywords. The variables are local variables., But java makes it mandatory to initialize all of the local variables in a program., 12. The automatic variables _________________________, a) Must be declared after its use, b) Must be declared before using, c) Must be declared, can be anytime, d) Must not be initialized, View Answer, Answer: b, Explanation: All the automatic variables in a program must be declared before their use. The, compiler won’t allow any use of variable if those are not declared before their use., 13. Which error is produced if the automatic variables are used without declaration?, a) Undefined symbol, b) Memory error, c) Type mismatch, d) Statement missing, View Answer, Answer: a, Explanation: If the automatic variables are used without declaration or are used before the, declaration then the compiler throws an error. The error that the symbol is undefined. The, compiler must know everything before that can be used., advertisement, , 14. In Perl, using which operator are the local variables created?, a) Dot, b) Arrow, c) Scope resolution, d) my, View Answer, Answer: d, Explanation: The language perl supports local variables but the concept is bit different. And, if the values are not assigned to the local variables then it contains undef value., 15. How are automatic variables different from the instance variables?, a) Automatic variables are initialized automatically but instances are not, b) Automatic variables are given zero values initially and not instances, c) Instance variables have to be initialized explicitly and automatic implicitly, d) Instance variables are initialized implicitly while automatic are not, View Answer, Answer: d, Explanation: The automatic variables have to be initialized explicitly. But in case of
Page 319 :
instances, those are initialized automatically during execution of the program. The, conventions are mandatory., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Delete Operator, » Next - Object Oriented Programming Questions and Answers – Extern Variable, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Delete Operator, Object Oriented Programming Questions and Answers – Extern Variable, advertisement, advertisement, , Recommended Posts:, 1. C Programming Examples on Data-Structures, 2. C# Programming Examples on Matrix, 3. C# Programming Examples on Delegates, 4. Java Programming Examples on Exception Handling, 5. C Programming Examples on Numerical Problems & Algorithms, 6. C# Programming Examples on Mathematics, 7. C# Programming Examples on Events, 8. C# Programming Examples on Strings, 9. C Programming Examples on Bitwise Operations, 10. C Tutorials, 11. Java Programming Examples on Multithreading, 12. C# Programming Examples on Functions, 13. C Programming Examples on File Handling, 14. Java Programming Examples on Java.Lang, 15. C# Programming Examples on Interfaces, 16. C# Programming Examples on Exceptions, 17. C# Programming Examples on Threads, 18. Java Programming Examples on Inheritance, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement
Page 320 :
Object Oriented Programming Questions, and Answers – Extern Variable, « Prev, Next », , This set of Object Oriented Programming Questions and Answers for Campus interviews, focuses on “Extern Variable―., 1. What is extern variable?, a) Variables to be used that are declared in another object file, b) Variables to be used that are declared in another source file, c) Variables to be used that are declared in another executable file, d) Variables to be used that are declared in another program, View Answer, Answer: b, Explanation: The variables that are declared in another source file can be accessed in other, files using extern variables. The extern variables must be mentioned explicitly. The source, file is included to use its variables., advertisement, , 2. Which among the following is a correct statement for variables?, a) Variable can be declared many times, b) Variable can be declared only one time, c) Variable declaration can’t be done more than ones, d) Variable declaration is always done more than one time, View Answer, Answer: a, Explanation: The variables can be declared any number of times. There is no restriction on, how many times a single variables can be declared. Declaration is just an indication that the, variable will be used in the program., 3. Which among the following is true for the variables?, a) Variable can be defined only once, b) Variable can be defined any number of times, c) Variable must be defined more than one time, d) Variable can be defined in different files, View Answer, Answer: a, Explanation: The variables can be defined only once. Once the variable is defined, then it, can’t be declared again. The definition of a variable is actual allocation of memory for the, variable., 4. To use extern variable _____________________, a) The source file must not be included in the new file code
Page 321 :
b) The source file itself must be used for a new program, c) The source file must be included in the new file, d) The source file doesn’t matter for extern variables, View Answer, Answer: c, Explanation: The source file must be included in the file which needs to use the extern, variable. This is done to ensure that the variables that are already declared can be used again., Only the declarations are used from one file to another., 5. What does a header file contain for an extern variable?, a) Only declaration of variables, b) Only definition of variables, c) Both declaration and definition of variables, d) Neither declaration nor definition, View Answer, Answer: a, Explanation: The header file only contains the declaration of variables that are extern. It, doesn’t contain any static variable definitions., advertisement, , 6. Which condition is true if the extern variable is used in a file?, a) All the header files declare it, b) Only few required files declare it, c) All header files declared it if required, d) Only one header file should declare it, View Answer, Answer: d, Explanation: Only one header file should declare the extern variable to be used. There must, not be more than one file declaring the same extern variable. This is to ensure that there is no, ambiguity in using the extern variable., 7. Whenever a function is declared in a program _____________________, a) extern can be used only in some special cases, b) extern can’t be used, c) function is extern by default, d) it can’t be made extern, View Answer, Answer: c, Explanation: Even if we don’t specify a function to be extern, by default all the functions, are exter. The compiler adds the keyword at the beginning of the function declaration. If there, is an extern function to be used then it will be used otherwise the new function only will be, used., 8. Even if a variable is not declared as extern, it is extern by default., a) True
Page 322 :
b) False, View Answer, Answerr: b, Explanation: The statement is false. The variables are not extern by default. If those are made, extern by default, then the memory will never be allocated for those extern variables. Hence, we make the variables extern explicitly., 9. Which of the following results in the allocation of memory for the extern variables?, a) Declaration, b) Definition, c) Including file, d) Memory is not allocated for extern variables, View Answer, Answer: b, Explanation: The memory for the extern variables are allocated due to their definition. When, the variables are declared, it only indicates the compiler that the variable is going to be used, somewhere. But definition makes the compiler to allocate the memory for the variables., 10. Which is the correct syntax for extern variable declaration?, a) extern data_type variable_name;, b) extern variable_name;, c) data_type variable_name extern;, d) extern (data_type)variable_name;, View Answer, Answer: a, Explanation: The syntax firstly contains the keyword extern. Then the data type of the, variable is given. Then the variabel name is mentioned by which it will be used in the, program., advertisement, , 11. Which is the correct syntax for extern function declaration?, a) extern function_name(argument_list);, b) extern return_type function_name(argument_list);, c) extern (return_type)function_name(argument_list);, d) return_type extern function_name(argument_list);, View Answer, Answer: b, Explanation: The syntax must contain the keyword extern first, to denote that the function is, extern. Though the function are extern by default but among the given choices, it should, contain the keyword, for explicit declaration. Then the usual function declaration follows., 12. What will be the output of the program?, extern int var;, int main(void), {, var = 10;
Page 323 :
var++;, cout<<var;, }, , a) 10, b) 11, c) Run time error, d) Compile time error, View Answer, Answer: d, Explanation: The program gives the compiler time error. There is no definition given for the, extern variables. This is not allowed and hence we get a compile time error., 13. If the definition is given in the header file that we include then ________________, a) The program can run successfully, b) Also the program should define the extern variable, c) The extern variable must contain two definitions, d) Extern variable can’t be used in the program, View Answer, Answer: a, Explanation: The program runs successfully. This is because only one definition of any, variable is allowed. And hence the definition from the source file that is included will be, used., advertisement, , 14. If extern variable is initialized with the declaration then _______________________, a) Also the header file with definition is required, b) The header file with definition must be included, c) There is no need to include any other header file for definition, d) The extern variable produces compile time error, View Answer, Answer: c, Explanation: When the value for the extern variable is defined with its declaration, then there, is no need to include any file for the definition of the variable. The Initialization acts as a, definition for the extern variable in the file itself., 15. Why are functions extern by default?, a) Because functions are always private, b) Because those are not visible throughout the program, c) Because those can’t be accessed in all parts of the program, d) Because those are visible throughout the program, View Answer, Answer: a, Explanation: The program have all of its functions visible throughout the program usually., Also, there is no specific value that a function must contain. Hence the functions are extern, by default.
Page 324 :
Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming for Campus Interviews, here is, complete set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Automatic Variable, » Next - Object Oriented Programming Questions and Answers – Inbuilt Classes, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Automatic Variable, Object Oriented Programming Questions and Answers – Inbuilt Classes, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on String Handling, 2. C Programming Examples, 3. C# Programming Examples on Delegates, 4. C# Programming Examples on Interfaces, 5. Python Programming Examples, 6. Java Programming Examples on Networking, 7. C# Programming Examples on Functions, 8. Java Programming Examples on Utility Classes, 9. C# Programming Examples on LINQ, 10. C Questions and Answers, 11. Java Programming Examples, 12. C Tutorials, 13. Ruby Programming Questions and Answers, 14. Java Programming Examples on File Handling, 15. Java Programming Examples on Java.Lang, 16. C# Programming Examples on Files, 17. Java Programming Examples on Inheritance, 18. C Programming Examples on File Handling, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – Inbuilt Classes, « Prev, Next »
Page 325 :
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “Inbuilt Classes―., 1. What are inbuilt classes?, a) The predefined classes in a language, b) The classes that are defined by the user, c) The classes which are meant to be modified by the user, d) The classes which can’t be used by the user, View Answer, Answer: a, Explanation: The classes that are already provided in a programming language for use are, inbuilt classes. These classes provide some functions or objects that can be used by the, programmer for easier code., advertisement, , 2. Inbuilt class __________________________, a) Must be included before use, b) Are not necessary to be included for use, c) Are used by the compiler only, d) Can be modified by programmer always, View Answer, Answer: a, Explanation: The inbuilt classes must be included in the program. Whenever some functions, are used, they must have a declaration before use. The same is the case with classes., 3. What doesn’t inbuilt classes contain?, a) Function prototype, b) Function declaration, c) Function definitions, d) Objects, View Answer, Answer: c, Explanation: The classes contain the definitions of the special functions that are provided for, the programmers use. Those functions can be used to make the programming easy and to, reuse the already existing code., 4. Which among the following not an inbuilt class in C++?, a) System, b) Color, c) String, d) Functions, View Answer, Answer: d, Explanation: There is no inbuilt class named function in java. The others are classes already, provided in java. All those classes contain some special functions to be used in programming.
Page 326 :
5. What is the InputStream class meant for?, a) To handle all input streams, b) To handle all output streams, c) To handle all input and output streams, d) To handle only input from file, View Answer, Answer: a, Explanation: The InputStream is an inbuilt class which is used to handle all the tasks related, to input handling. This class extends input from keyboard or file or any other possible input, stream., advertisement, , 6. Which statement is true for the Array class?, a) Arrays can have variable length, b) The length array can be changed, c) Each class has an associated Array class, d) Arrays can contain different type of values, View Answer, Answer: c, Explanation: The Array class is associated with all the other classes. This gives us the, flexibility to declare an array of any type. The index goes from 0 to n, where n is some fixed, size for array., 7. What is the use of Math class?, a) To use the mathematical functions with strings, b) To use the mathematical functions, c) To suppress the use of mathematical functions, d) To complex the calculations, View Answer, Answer: b, Explanation: The Math class is provided with some special functions. These functions can be, used to calculate and get result of some special and usual mathematical functions. We, don’t have to write the code to calculate the trigonometric function results, instead we can, use Math functions., 8. DataInputStream is derived from ______________________, a) StreamingInput, b) StreamedInput, c) StreameInput, d) StreamInput, View Answer, Answer: d, Explanation: The DataInputStream is more specific class for operating on specific type of, data inputs. This is used to read data of specific type. The same can be used to read data in a, specific format.
Page 327 :
9. Which attribute can be used to get the size of an array?, a) Size.Array, b) Array.Size, c) Array_name.length, d) length.Array_name, View Answer, Answer: c, Explanation: The array name is given of which the length have to be calculated. The array, length is stored in the attribute length. Hence we access it using dot operator., advertisement, , 10. Number class can’t manipulate ____________________, a) Integer values, b) Float values, c) Byte values, d) Character values, View Answer, Answer: d, Explanation: The Number class is used to work with all the number type of values. The, integers, float, double, byte etc. are all number type values. Character is not a number value., 11. Which function should be used to exit from the program that is provided by System class?, a) exit(int);, b) gc();, c) terminate();, d) halt();, View Answer, Answer: a, Explanation: The exit function should be used to terminate the program. The function is, passed with an argument. The argument indicated the type of error occurred., 12. Which class contain runFinalization() method?, a) Finalize, b) System, c) Final, d) SystemFinal, View Answer, Answer: b, Explanation: The runFinalization() Function is defined in the System class. The function is, used to finalize an object which undergo destruction. The action is required to terminate the, object properly., 13. What does load(String)::= function do, in System class?, a) Loads dynamic library for a path name, b) Loads all the dynamic libraries, c) Loads all the Number in string format
Page 328 :
d) Loads the processor with calculations, View Answer, Answer: a, Explanation: Only the specified path named dynamic libraries are loaded. All the dynamic, libraries can’t be loaded at a time. Hence we use this function for specific libraries., advertisement, , 14. Which is not a System class variable?, a) err, b) out, c) in, d) put, View Answer, Answer: d, Explanation: Put is not a System class variable. The most general and basic variables are err,, out and in. The variables can handle most of the tasks performed in a program., 15. Which package contains the utility classes?, a) java.lang, b) java.utility, c) java.util, d) java.io, View Answer, Answer: c, Explanation: The package java.util contains all the utility classes. This package also contains, generic data structures, date, time etc. These can be used in any java program, you just have, to include java.util package., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Extern Variable, » Next - Object Oriented Programming Questions and Answers – IO Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Extern Variable, Object Oriented Programming Questions and Answers – IO Class, advertisement, advertisement
Page 329 :
Recommended Posts:, 1. C Programming Examples on Searching and Sorting, 2. C Programming Examples on Stacks & Queues, 3. Java Programming Examples on Numerical Problems & Algorithms, 4. Java Programming Examples on File Handling, 5. Java Programming Examples on Mathematical Functions, 6. C Programming Examples on Arrays, 7. C++ Programming Examples on STL, 8. Java Programming Examples on Data-Structures, 9. Java Programming Examples on Networking, 10. Java Programming Examples on Java.Lang, 11. Java Programming Examples, 12. Java Programming Examples on Inheritance, 13. Java Programming Examples on Collections, 14. Java Programming Examples on Arrays, 15. Java Programming Examples on Collection API, 16. C# Programming Examples on Arrays, 17. Java Programming Examples on Exception Handling, 18. Java Programming Examples on Utility Classes, 19. Java Programming Examples on Classes, 20. Object Oriented Programming Questions and Answers – Pointer to Objects, advertisement, , Object Oriented Programming Questions, and Answers – IO Class, « Prev, Next », , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “IO Class―., 1. What is the use of IO class?, a) To handle all the input operations, b) To handle all the output operations, c) To handle all the input and output operations, d) To handle all the input and output to the standard input, View Answer, Answer: c, Explanation: The IO class provides functions that can be used to handle input and output, operations. All the inputs from standard input and standard output, and also from the files can, be handled. This gives the flexibility to make the programs more user friendly., advertisement
Page 330 :
2. IO class provides input and output through ______________________, a) Data streams, b) Serialization, c) File system, d) Data streams, serialization and file system, View Answer, Answer: d, Explanation: The IO classes are made such that those can support the input and output from, any type of source or destination. The input can be taken from system file and standard input, and also some special devices if conned. Same is case to show the output., 3. Which among the following class contains the methods to access character based console, device?, a) Console, b) File, c) Device, d) Pipe, View Answer, Answer: a, Explanation: The Console class contains the methods to access the character based devices., The devices which can stream the data as character set. All those devices can be made use of, by using the methods of class Console., 4. File class is ____________________________, a) An abstract of file representation only, b) An abstract of path names only, c) An abstract which can be used to represent path names or file, d) An abstract which can represent a file in any format, View Answer, Answer: c, Explanation: The File class is made to operate with the files. The file can be of any type. All, the input and output operations that have to be performed on a file can be done using File, class object., 5. What is a FileDescriptor?, a) A handle for machine specific structure of an open file, b) A handle for program specific structure of an open file, c) A handle for compiler specific structure of an open file, d) A handle for representing device files structure, View Answer, Answer: a, Explanation: The machine specific structure of an open file have to be handled in some, special ways. FileDescriptor class can handle those files. The FileDescriptor can also handle, open socket, another source, sink of bytes., advertisement
Page 331 :
6. FileInputStream _________________________, a) Gets the input stream from any device file, b) Gets the input stream from any open socket, c) Gets the input stream from any cache, d) Gets the input stream from any open file only, View Answer, Answer: d, Explanation: The most specific answer is that the FileInputStream can only be used for the, opened files. The class can work only for the file type. No socket or another source are, allowed to be accessed., 7. What does FilePermission class do?, a) This class is used to give permission rights to a file, b) This class is used to restrict the use of permissions, c) This class is used to represent device access permissions, d) This class is used to represent file access permissions, View Answer, Answer: d, Explanation: The FilePermission can’t get access to the device access permissions. The, Permission is given to a file when it is created or otherwise when a privileged user changes it., Then these permission rights can be accessed using the FilePermission class., 8. Which class among the following makes incorrect assumptions?, a) LineNumberInputStream, b) LineNumberReader, c) LineReader, d) LineBuffer, View Answer, Answer: a, Explanation: The LineNumberInputStream class makes false assumptions. The false, assumption is that it assumes, all the byte data is a character. Which is actually not the case,, instead the character have one byte memory space., 9. Reader class is _________________, a) Used to read from files, b) Abstract class to read character streams, c) Abstract class to input character streams, d) Used to take input from standard input stream, View Answer, Answer: b, Explanation: The Reader class is an abstract class that can be used to read characters stream., It can’t be used for any kind of input. It can just read the existing data., advertisement, , 10. Which class can handle IO class interrupt?, a) ExceptionIO
Page 332 :
b) InteruptedIO, c) InteruptedIOException, d) IOInteruptException, View Answer, Answer: c, Explanation: The only class which handles the IO class interrupts is InteruptedIOException, class. This class is specially provided to handle any case that involves the execution interrupt., 11. StringReader handles _____________________, a) Any character stream, b) A character stream whose source is an array, c) A character stream whose source is character array, d) A character stream whose source is String only, View Answer, Answer: d, Explanation: The StringReader can only work with the string type data. Even if a character, array is given, it might produce some errors in code. Hence only the string values can be, handled properly., 12. Which exception handler can be used when character encoding is not supported?, a) UnsupportedException, b) UnsupportedEncodingException, c) SupportException, d) EncodingException, View Answer, Answer: b, Explanation: The encoding that is unsupported in a system can be handled. The exception, handler is UnSupportedEncodingException class. An object of this class can be created, which will catch the exception and handle it., 13. PushBackReader allows the streams to be pushed back to the stream., a) True, b) False, View Answer, Answer: a, Explanation: The PushBackReader allows the character streams handling. The main feature is, that the stream can be pushed back to the stream. This is used in special cases of handling, input stream., advertisement, , 14. RandomAccessFile can be used to _______________________, a) Read from a random access file, b) Write to a random access file, c) Read and write to a random access file, d) Restricts read and write to a random access file, View Answer
Page 333 :
Answer: c, Explanation: The RandomAccessFile class instance can be created to handle input and output, operations to a random access file. It first checks the permissions on the file and then any, required operation can be done on a random access file. Comparatively faster than other files, access., 15. Which among the following is a serialization descriptor for any class?, a) StreamClass, b) ObjectStreamClass, c) ObjectStream, d) StreamObjectClass, View Answer, Answer: b, Explanation: The ObjectStreamClass object can be created to handle serializations. The class, is provided specially for the serializations. It is descriptor like we have a file descriptor to, handle/access files., Sanfoundry Global Education & Learning Series – Object Oriented Programming, (OOPs)., To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+, Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Object Oriented Programming Questions and Answers – Inbuilt Classes, » Next - Object Oriented Programming Questions and Answers – String Class, Categories Object Oriented Programming MCQs Post navigation, Object Oriented Programming Questions and Answers – Inbuilt Classes, Object Oriented Programming Questions and Answers – String Class, advertisement, advertisement, , Recommended Posts:, 1. Java Programming Examples on Networking, 2. C# Programming Examples on Data Structures, 3. C# Basic Programming Examples, 4. Java Programming Examples on String Handling, 5. C# Programming Examples on Functions, 6. C Programming Examples, 7. Java Programming Examples on Event Handling, 8. Java Programming Examples on Exception Handling, 9. Java Programming Examples on Utility Classes, 10. Java Programming Examples on Collections, 11. Java Programming Examples on Classes
Page 334 :
12. 100+ Java Android Programming Examples, 13. Java Programming Examples on Java.Lang, 14. C# Programming Examples, 15. C Programming Examples on File Handling, 16. Java Programming Examples, 17. Java Programming Examples on Inheritance, 18. C# Programming Examples on Files, 19. Java Programming Examples on File Handling, 20. Object Oriented Programming Questions and Answers, advertisement, , Object Oriented Programming Questions, and Answers – String Class, « Prev, , This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers, (MCQs) focuses on “String Class―., 1. Which is a true statement for object of String class?, a) Object are immutable, b) Object are mutable, c) Object are created only once, d) Object can’t be created, View Answer, Answer: a, Explanation: The object of string class are mostly immutable. This means that the String, objects are constant. These can’t be changed once created., advertisement, , 2. How to declare an object of class String?, a) String object_Name = value;, b) String object_name = new;, c) String object_name= new value;, d) String object_name= value new;, View Answer, Answer: a, Explanation: The class name String is given. And then the object name is mentioned. There, are two ways to declare and initialize the string. Either by giving direct string value or by, using new keyword. But if new operator is used, constructor of String class have to be called., From the given options, the direct string value declaration is correct., 3. What does function length do in String class?, a) Returns length of string including null character, b) Returns length of string excluding null character
Page 335 :
c) Returns length of substring, d) Returns size of string in bytes, View Answer, Answer: b, Explanation: The length function returns the length of string. The length is the number of, characters in the string but the last null character is not counted. The string length can be used, to loop through each character in the string., 4. Which is the function to get the character present at a particular index in the string?, a) char charAt(index);, b) char charIn(StringName);, c) char charAt(StringName);, d) char charIn(index);, View Answer, Answer: a, Explanation: The function can be called using dot operator with the string object. Char is the, return type of the function to return the character at specified position. The index must be an, integer value, less than the length of string., 5. If only one parameter is passed to substring function then __________________, a) It returns the character at the specified position, b) It returns the string of length 1 from the specified index, c) It returns the string from specified index till the end, d) It returns the string from starting of string till the specified index, View Answer, Answer: c, Explanation: The substring function returns a string value. The string is the substring starting, from the specified index till the end. The substring function have to be called with the object, of string class., advertisement, , 6. If two index are given as argument to substring function then ___________________, a) String of length equal to sum of two arguments is returned, b) String starting from first index and of length equal to send argument, c) String starting from first index and of length equal to sum of two arguments, d) String starting from first index and ending at second index position, View Answer, Answer: d, Explanation: A value of string type is returned from this function. The returned string is a, substring that starts from the first argument position, till the second index position. The, indices must be less than the length of actual string., 7. String class have a concat() function that is used to _____________________, a) Replace old string by new string, b) Add two strings, c) Append one string at end of another string
Page 336 :
d) Remove a string from end of one string, View Answer, Answer: c, Explanation: The concat function is used to append string into another string. The new string, is always appended at the end of source string. The target string is appended as it is and the, whole string is then ended by null character., 8. The function lastIndexOf() is used to ___________________, a) Get the index of last occurrence of specified character in argument, b) Get the index of first occurrence of specified character in argument, c) Get the index of last occurrence of first character in string, d) Get the index of last occurrence of last character of string, View Answer, Answer: a, Explanation: The function is used to get the last occurrence index of a character present in a, string. The return type is char. Single character is returned. The function is used with a string, object and the target character is passed as its argument., 9. Function equals() is _______________ and equalIgnoreCase() is _________________, a) Case Insensitive, case insensitive, b) Case sensitive, Case insensitive, c) Case sensitive, case sensitive, d) Case insensitive, case sensitive, View Answer, Answer: b, Explanation: Both the functions return Boolean value. The function equal() is case sensitive, and returns false even if a single character is case different in two strings. The other function, ignores the case sensitivity and only checks if the spellings are same., advertisement, , 10. The compareTo() function is used to ________________, a) Compare strings value to string object, b) Compare string value to string value, c) Compare string object to another string object, d) Compare string object to another string value, View Answer, Answer: c, Explanation: The source and target must be objects of the string class. The compare is always, case sensitive. To compare two string objects without case sensitivity then we can use, compareToIgnoreCase() function., 11. String class provides function toUpper() to _____________________, a) Convert first character to uppercase, b) Convert last character to uppercase, c) Convert the whole string characters to uppercase
Page 337 :
d) Convert uppercase to lower and lower to uppercases, View Answer, Answer: c, Explanation: The function is used to convert each character of the string. If the character is, already uppercase then it remains the same. But if some character is in lowercase then it will, be converted to uppercase., 12. String trim() function is used to _______________________, a) Remove all the white spaces from the string, b) Remove white space from start of string, c) Remove white space at end of string, d) Remove white space from both the ends of string, View Answer, Answer: d, Explanation: The function is used to remove any white space from both the ends of a given, string. The white space include space, tab, next line etc. It will be removed both from the, starting of string and from the end of string., 13. Function replace() accepts _____________ arguments., a) 1, b) 2, c) 3, d) 4, View Answer, Answer: b, Explanation: The first argument is the target character. This target character will be replaced, by another character. The new character is the second argument to the function. Only the, characters can be passed as argument, not a string., advertisement, , 14. If two arguments are passed to the indexOf() function then ___________________, a) Second argument indicates the occurrence number of specified character from starting, b) Second argument indicates the occurrence number of specified character from end, c) Second argument indicates the index of the character in first argument, d) Second argument indicates the index of the character from the last of the string, View Answer, Answer: a, Explanation: The string may have more than one occurrence of a character. We use this, function to get the index at which the specified number of times a specific character has, occurred in a string. For example, we can get the index of 5th occurrence of character, “j― in a string., 15. The string class deals with string of only character type., a) True, b) False, View Answer
Page 338 :
10. For which of the following conditions rigid construction is required?, a) fixed beam supported by girder, b) cantilever beam supported by girder, c) overhanging beam, d) overhanging beam supported by girder, View Answer, Answer: b, Explanation: Rigid connections are necessary if a cantilever beam is supported by girder., Rigid connections may be provided for moment continuity between secondary beams., 11. When cantilever beam is supported by girder, the end of cantilever will transfer, a) shear force, b) torsion, c) bending moment, d) shear force and bending moment, View Answer, Answer: d, Explanation: When cantilever beam is supported by girder, the end of cantilever will transfer, shear force and bending moment and this bending moment will be transferred to primary, beam as torsion., 12. In a beam-beam connection, which type of connection is used when top flanges are, required to be at same level ?, a) bracket connection, b) combined splice plate/end plate connection, c) combined splice plate/bracket connection, d) moment resistant connection, View Answer, Answer: b, Explanation: In a beam-beam connection, when top flanges are required to be at same level, combined splice plate/end plate connection with coped ends is used. HSFG bolts may be, utilized in these connections for avoiding local rotation., Sanfoundry Global Education & Learning Series – Design of Steel Structures., advertisement, , To practice all areas of Design of Steel Structures for Experienced people, here is complete, set of 1000+ Multiple Choice Questions and Answers., Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our, social networks below and stay updated with latest contests, videos, internships and jobs!, Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest, « Prev - Design of Steel Structures Questions and Answers – Simple Connections, » Next - Design of Steel Structures Questions and Answers – Beam and Column Splices
Page 339 :
Techvines Coders Union, , Join our telegram Community for more Support- https://t.me/Techvines_Coders_Union, , OOP Question Bank for Final Exam, (2019- Pattern), Sr. No, , 1, 2, 3, , 4, 5, 6, , 7, , 8, , 9, , 10, , 11, , Unit I, Questions, Every class has at least one constructor function, even when none, is declared. A) True B) False, Can constructors be overloaded? A) True B) False, What is the difference between struct and class in terms of, Access Modifier?, A. By default all the struct members are private while by, default class members are public., B. By default all the struct members are protected while by, default class members are private., C. By default all the struct members are public while by, default class members are private, D. By default all the struct members are public while by, default class members are protected, The default access level assigned to members of a class is ______, A. Public B. Private C. Protected D. Needs to be assigned, Which of the following operators allow defining the member, functions of a class outside the class?, A. Scope Resolution(: : ) B. (Dpt) Operator C. Conditional, operator D. Dereferencing Operator(->), Which type of class has only one unique value for all the objects, of that same class?, A. Static B. Friend C. Abstract D. Both A and B, What is a constructor?, A. A class automatically called whenever a new object of, this class is created, B. A class automatically called whenever a new object of, this class is destroyed, C. A function automatically called whenever a new object of, this class is created., D. A function automatically called whenever a new object of, this class is destroyed., Under what conditions a destructor destroys an object?, A Scope of existence has finished B. Object dynamically, assigned and it is released using the operator delete. C. Program, terminated. D. All of the above, If a member needs to have same value for all the objects of that, same class, declare the member as, A. Static B. Void C. Friend D. Constant, Variables declared in the body of a particular member function, are known as data members and can be used in all member, , Marks, , Correct, Answer, , 1, , A, , 1, 1, , A, C, , 1, , B, , 1, 1, , A, A, , 1, , A, , 1, , C, , 1, , D, , 1, , A, , 1, , B
Page 340 :
2, , A., , 17, , A . True B. False, In a class definition, data or functions designated private are, accessible, A. to any function in the program., B. only if you know the password., C. To member functions of that class., D. Only to public members of the class., Dividing a program into functions, A. is the key to object-oriented programming., B. makes the program easier to conceptualize., C. may reduce the size of the program., D. Option B and C, A function argument is, A. a variable in the function that receives a value from the, calling program., B. a way that functions resist accepting the calling program’s, values., C. a value sent to the function by the calling program., D. a value returned by the function to the calling program., When arguments are passed by value, the function works with the, original arguments in the calling program. A. True B. False, How many values can be returned from a function?, A. 0 B.1 C. 2 D. 3, What is the Value of size?, , 18, , A. 28 B. 32 C. 20 D. 24, What will be the output of the program?, , 12, , 13, , 14, , 15, 16, , 1, , C0, , 1, , D, , 1, , C, , 1, , B, , 1, , B, , 2, , C, , 2, , C
Page 341 :
3, , 19, , A. 1 B. Default Value C.Compiler Error D. None of the, above, What is the output of the program?, , 2, , 20, , A. 0 0 B. x=0; y=0; C 0 D. Compilation Error, Which function will change the state of the object?, , 2, , A, , 2, , C, , 21, , A. Only set() B. Only display() C. display and set both, E. None of the above, What will be the output of the given program?, A. Compilation Error: display() cannot be accessed in, application, B. Compilation Error:Test class object cannot be accessed in, function Demo, C. Compilation Error: Variable x is private in Test, D. Both A and B
Page 342 :
4, , 22, , 24, , Which of the following is FALSE about references in C++, A. A reference must be initialized when declared, B. Once a reference is created, it cannot be later made to, reference another object; it cannot be reset, C. References cannot be NULL, D. References cannot refer to constant value, What will be the output of following program?, , 1, , D, , 2, , C, , 1, , A, , 1, , D, , 1, , C, , #include <iostream>, using namespace std;, class Test, {, public:, Test() { cout <<"Hello from Test() "; }, } a;, , 25, , int main(), {, cout <<"Main Started ";, return 0;, }, A. Main Started, B. Main Started Hello from Test(), C. Hello from Test() Main Started, D. Compiler Error: Global objects are not allowed, In C++ ..................... operator is used for Dynamic memory, allocation. A. :: B. new C. Membership (Dot Operator), E. Conditional ?:, , 26, , 27, , Which of the following header file includes definition of cin and, cout?, A. istream.h B. ostream.h C. iomanip D. iostream, cout is a/an __________
Page 343 :
5, , 28, , 29, , 30, 31, 32, 33, , 34, 35, 36, , 37, 38, 39, , 40, , 41, , A. operator B. function C. Object 4. Dariable, ......... is a member function with the same name as the class., A. Friend function B. Constructor, C. Destructor D.None of the above, Which is not the feature of constructor?, A. It cannot be inherited. B. It should be declared in Private., C. It do n1ot have return type D. All of above, Which is not type of constructor?, A. Default B. Copy C. Parameterized D. None of the above, Objects are destroyed in the reverse order of its creation. A. True, B. False, .... constructor is used for copying the object of same class type., A. Default B. Copy C. Parameterized D. None of the above, The function inside a class is called as ......., A. Friend function B. Member Function C. Class Function D. All, of the above, How many objects can be created by a class?, A. 1 B. 2 C. 3. D. Any Number ., Default return type of C++ main( ) is ....., A. float B. int C. void D. pointer, Enumerated data type is ........, A. User-defined data type B. Built-In/ Fundamental data type, C. Derived data yype D. All of the above, Object-oriented programming follows Top-down approach., A. True B. False, Which type is best suited to represent the logical values?, A. Integer B. boolean C. character D. All, Inline functions are, A. Declared in the class defined outside the class, B. Defined outside the class using keyword inline, C. Defined inside the class using keyword inline, D. None of the above, Which of the following functions are performed by a constructor?, A. Construct a new class B. Construct a new object, C. Construct a new function D. Initialize objects, What will be the ouput of following :, #include <stdio.h>, using namespace std;, int array1[] = {1200, 200, 2300, 1230, 1543};, int array2[] = {12, 14, 16, 18, 20};, int temp, result = 0;, int main(), {, for (temp = 0; temp <5; temp++) {, result += array1[temp];, }, , 1, , B, , 1, , B, , 1, , D, , 1, , A, , 1, , B, , 1, , B, , 1, , D, , 1, , B, , 1, , A, , 1, , B, , 1, , B, , 1, , B, , 1, , D, , 2, , B
Page 344 :
6, , for (temp = 0; temp <4; temp++) {, result += array2[temp];, }, cout <<result;, return 0;, , 42, 43, 44, 45, , }, A. 6553 B. 6533 C. 6522 C. 12200, In procedural programming the focus in on …..........., A. Data B. Function C. Structure D. Pointers, In object oriented programming the focus major is on …......., A. Data B. Function C. Structure D. Pointers, Which of the following data type does not return anything?, A. int B. short C. long D. void, Which of the following statements is correct for a static member, function?, , 1, , B, , 1, , A, , 1, , D, , 1, , C, , 1, , D, , 2, , A, , 2, , B, , 1. It can access only other static members of its class., 2. It can be called using the class name, instead of objects, A. Only 1 is correct B. Only 2 is correct C. Both 1 and 2 are, correct C. Both 1 and 2 are incorrect, 46, , When a copy constructor may be called?, A. When an object of the class is returned by value B. When an, object of the class is passed (to a function) by value as an, argument C. When an object is constructed based on another, object of the same class D. All, , 47, , Output of following program?, #include<iostream>, using namespace std;, class Point {, Point() { cout <<"Constructor called"; }, };, int main(), {, Point t1;, return 0;, }, A. Compiler Error B. Run-time Error C. Constructor Called D., No Error, , 48, , What will be the output of the program?, #include<iostream>, using namespace std;, class Point {, public:
Page 345 :
7, , Point() { cout <<"Constructor called"; }, };, int main(), {, Point t1,t2;, return 0;, }, A. Constructor called B. Constructor called Constructor called, C. Compiler Error D. Nothing, 49, , What will be the output of the program?, , 2, , B, , 1, , A, , 1, , C, , 1, , A, , 1, , C, , 1, , D, , #include<iostream>, using namespace std;, class X, {, public:, int x;, };, , 50, 51, , 52, , 53, , 54, , int main(), {, X a = {10};, cout <<a.x <<" ";, return 0;, }, A. 10 followed by Garbage Value B. 10 C. Compiler Error D. 0, The term __________ means the ability to take many forms., A. Polymorphism B. Inheritance C. Encapsulation D. Abstraction, The mechanism that binds code and data together and keeps them, secure from outside world is known as, A. Polymorphism B. Inheritance C. Encapsulation D. Abstraction, Member functions, when defined within the class specification, A. Are always inline B. Are not inline C. Are inline by default,, unless they are too big or too complicated D. Are not inline by, default., When the compiler cannot differentiate between two overloaded, constructors, they are called, A. Overloaded B. Destructed C. Ambiguous D. Audacious, In which case is it mandatory to provide a destructor in a class?, A. Almost in every class B. Class for which two or more than, two objects will be created C. Class for which copy constructor is, defined D. Class whose objects will be created dynamically
Page 346 :
8, , 55, 56, , 57, , 58, , 59, 60, 61, 62, , 63, , 64, , 65, 66, , Another term for __________ is data hiding., A. Encapsulation B. Abstraction C. Privacy D. None of the above, The term __________ refers to a way of organizing classes that, share properties., A. Object-oriented B. encapsulation C. Polymorphism D., Inheritance, Encapsulation makes it easier to, A reuse and modify existing modules of code, B. write and read code by sharing method names., C. hide and protect data from external code., D. Both a and b., Inheritance makes it easier to:, A reuse and modify existing modules of code, B. write and read code by sharing method names., C. hide and protect data from external code., D. Both a and b., Which of the following is a C++ object?, A. cin B. >> C. iostream D. read(), Which of the following is the insertion operator?, A. >> B<< C. : : D. ., The term instantiation refers to the creation of:, A. Class B. Object C. method D. attribute, If you declare two objects as Customer firstCust, secondCust;, which of the following must be true?, A. Each object's non static data members will be stored in the, same memory location, B. Each object will be stored in the same memory location, C. Each object will have a unique memory address, D. You cannot declare two objects of the same class, A static data member is initialized with a value, A. within the class definition., B. outside the class definition, C. when the program is executed, D. never, If you want only one memory location to be reserved for a class, variable, no matter how many objects are instantiated, you should, declare the variable as, A. static B. inline C. volatile D. dynamic, The operator that releases previously allocated memory is _____, A. release B. return C. delete D. destroy, The new operator, A. returns a pointer to the variable, B. creates a variable called new, C. obtains memory for a new variable, D. tells how much memory is available, , 1, , A, , 1, , D, , 1, , C, , 1, , A, , 1, , A, , 1, , B, , 1, , B, , 1, , C, , 1, , B, , 1, , A, , 1, , C, , 1, , C
Page 347 :
9, , 67, , 68, 69, 70, , 71, 72, , 73, , 74, , 75, , A class defined within another class is:, A. Nested class B. Local Class C. Containership D., Encapsulation, Constructors never have explicit return type A. True B. False, , 1, , A, , 1, , A, , Can I Inherit constructor and destructor of a base class ? A. Yes, B. No, Given a class named Book, which of the following is not a valid, constructor?, A. Book ( ) { }, B. Book ( Book &b){ }, C. Book ( Book b) { }, D. Book (char* author, char* title) { }, Which value we cannot assign to reference?, A. int B. float C. unsigned D. null, #include <iostream>, using namespace std;, int main(), {, int a = 9;, int & aref = a;, a++;, cout << "The value of a is " << aref;, return 0;, }, A. 9 B. 10 C.11 D. Error, Identify the correct sentence regarding inequality between, reference and pointer., A. we can not create the array of reference., B. we can create the array of reference., C. we can use reference to reference., D. None, #include <iostream>, using namespace std;, int main(), {, int x;, int *p;, x = 5;, p = &x;, cout << *p;, return 0;, }, A. 5 B. 10 C. Memory Address D. None, , 1, , B, , 1, , C, , 1, , D, , 2, , B, , 1, , A, , 2, , A
Page 348 :
10, , OOP Question Bank for Final Theory Exam, (2019- Pattern), Unit-II, Sr., No, 1, , 2, , 3, , 4, , 5, 6, , 7, , 8, , 9, , 10, , Questions, The keyword friend appear in, A. private section of the class B. public section of the class C. Both, A and B D. None of the above, It is possible to declare as a friend, A. A member function B. A global function C. A class D. All of the, above, A friend function to a class, C cannot access, A. Private data members and member functions, B. Public data members and member functions, C. Protected data members and member functions, D. The data members of the derived class of C, Which of the following declarations are illegal?, A. void *ptr; B char *str=”hello”; C. char str=”hello” D. const *char, c;, Identify the operator that is NOT used with pointers, A & B * C -> D. >>, Which statement is true?, A. A base class inherits some of the properties of a derived class., B. A base class inherits all of the properties of a derived class., C. A derived class inherits some of the properties of a base class., D. A derived class inherits all of the properties of a base class., A pointer to the base class can hold address of, A. only base class object, B. only derived class object, C. base class object as well as derived class object, D. None of the above, When class B is inherited from class A, what is the order in which, the constructers of those classes are called, A. Class A first Class B next, B. Class B first Class A next, C. Class B's only as it is the child class, D. Class A's only as it is the parent class, C++ does not supports the following, A. Multiple Inheritance B. Multilevel C. Hierarchical D. None of, the above, The main intention of using inheritance is …........., A. to help in converting one data type to other, B. to hide the details of base class, , Marks Correct, Answer, 1, C, , 1, , D, , 1, , D, , 1, , C, , 1, , D, , 1, , D, , 1, , C, , 1, , A, , 1, , D, , 1, , C
Page 349 :
11, , 11, , 12, , 13, 14, 15, 16, 17, , 18, 19, 20, , 21, , 22, 23, , C. to extend the capabilities of base class, D. to help in modular programming, Is it fine to call delete twice for a pointer?, #include<iostream>, using namespace std;, int main(), {, int *ptr = new int;, delete ptr;, delete ptr;, return 0;, }, A. Yes B. No, Reusability is supported by following feature, A. Polymorphism B. Message passing C. Inheritance D. Operator, Overloading, Base class is also known as, A. Super class B. Parent Class C. Both a and b D. None of the above, Child class is also known as, A. Sub class B. Derived Class C. Both a and b D. Known class, Derived class cannot access from ______base class, A. Constructor B. Destructor C. Both D. Statement is false, We can derive a new class from a derived class, A. True B. False, What is syntax of deriving a new class from base class is___., A. class name, new class name, B. class name: access specifier class name, C. new class name, base class name, D. none of the above, Which constructor will initialize the base class data member, A. Base class B. Derived Class C. Derived Derived D. None, Inheritance can be done using :: symbol A. True B. False, When we derived a new class using more than one class then type of, inheritance is known as____., A. Multiple B. Multilevel C. Hierarchical D. Hybrid, When class B is derive from A , and class C is derived from B, this, kind of inheritance is known as ______., A. Multiple B. Multilevel C. Hierarchical D. Hybrid, class A: public B, public C is a type of inheritance, A. Multiple B. Multilevel C. Hierarchical D. Hybrid, Virtual base class is used to ____., A. to perform operator overloading, B. to perform function overloading, C. to remove ambiguity in hybrid inheritance, , 1, , B, , 1, , C, , 1, , C, , 1, , C, , 1, , C, , 1, , A, , 1, , B, , 1, , A, , 1, 1, , B, A, , 1, , B, , 1, , A, , 1, , C
Page 350 :
12, , D. all of the above, 24, , 27, , Make a correct sequence of a statement, i)destructor of derived class is called, ii)destructor of base class is called, iii)constructor of derived class is called, iv)constructor of base class is called, A. i,ii,iv,iii B. iv,iii,ii,I C. iv,iii,i,ii D. i,ii,iii,iv, If a base class contains a member function basefunc(), and a derived, class does not contain a function with this name, can an object of, the derived class access basefunc()?, A. Yes B. No, Assume a class Derv that is privately derived from class Base. An, object of class Derv located in main() can access, A. public members of Derv., B. protected members of Derv., C. private members of Derv., D. public members of Base., What is the output of the program?, , 28, 29, , #include <iostream>, #include <string>, using namespace std;, class Department {, public:, string dept;, Department(string d):dept(d) { }, void getDeptName() { cout <<dept; }, };, class Student : private Department {, public:, string name;, Student(string n = "Not entered", string d = "ATDC") :, name(n), Department(d) { }, using Department::getDeptName;, };, int main() {, Student s("CSE");, s.getDeptName();, return 0;, }, A. CSE B. ATDC C. Not entered D. Compilation Error, Inheritance can be done using :: symbol A. True B. False, Identify the lines on which the compiler will report an error., , 25, , 26, , #include <iostream>// ---1, , 1, , C, , 1, , A, , 1, , A, , 2, , B, , 1, 2, , B, D
Page 351 :
13, , 30, , 31, , using namespace std; // ---2, class Base { // ---3, int var_; // ---4, public: // ---5, Base():var_(0){} // ---6, }; // ---7, class Derived: public Base { public: // ---8, int varD_; // ---9, void print () { cout <<var_; } // ---10, }; // ---11, int main() { // ---12, Derived d; // ---13, d.var_ = 1; // ---14, d.varD_ = 1; // ---15, cout <<d.var_ <<""<<d.varD_; // ---16, return 0; // ---17, } // ---18, A. 6, 10, 14, 15 B. 6, 15 C. 6, 14, 16 D. 10, 14, 16, #include <iostream>, using namespace std;, class Base { public:, int var_;, void func(int){}, };, class Derived: public Base { public:, int varD_;, void func(int){}2, };, int main() {, Derived d;, d.func(1);, return 0;, }, Which of the following function will be invoked by d.func(1)?, A. Base::func(int), B. Derived::func(int), C. Compilation Error, D. None of the above, What is the output of the following program?, #include<iostream>, #include<string>, using namespace std;, class Base {, public:, void func_f1(int i) { cout <<"In base func_f1 "; }, , 2, , B, , 2, , B
Page 354 :
16, , 35, , 36, , 37, , 38, , 39, 40, , What will be the output of the program?, #include <iostream>, using namespace std;, class Room {, int number;, public:, Room(int num = 0): number(num) { }, void dimension() { cout <<number <<"Rooms "; }, };, class Building {, public:, Building() : ro(100) { }, void Build() { ro.dimension(); }, private:, Room ro;, };, int main() {, Building B;, B.Build();, return 0;, }, A. 0 Rooms B. 100 Rooms C. Compilation Error: ro is private D., None of the mentioned, When deriving a class from with protected inheritance, public, members of the base class become___________ members of the, derived class, and protected members of the base class become, _____________ members of the derived class., A. protected, protected. B. public, private C. private, private, D. Private, protected, When deriving a class with public inheritance, public members of, the base class become __________ members of the derived class,, and protected members of the base class become, ___________members of the derived class., A. private, private B. public, protected. C. protected, protected D., Private, protected, Which of the following is true about this pointer?, A. It is passed as a hidden argument to all function calls, B. It is passed as a hidden argument to all non-static function calls, C. It is passed as a hidden argument to all static functions, D. None of the above, The inheritance is described as a _____ relationship, A. has a B. is a C. association D. None of these, When the object of derived class expire, first the _______ is, invoked followed by the ________., A. derived class constructor, base class destructor, , 2, , B, , 1, , A, , 1, , B, , 1, , B, , 1, , B, , 1, , B
Page 355 :
17, , 41, , 42, , 43, , 44, 45, , 46, , 47, , 48, , B. derived class destructor , base class destructor, C. base class destructor , derived class destructor, D. none of these, If class A is a friend class of class B, if class B is friend class of, class C then_______, A. class C is friend class of A, B. class A is friend class of C, C. class A and class C do not have any friendship relation., D. none of these, When base class pointer points to derived class object___________, A. it can access only base class members, B. it can access only derived class members, C. both base class &derived class members, D. None of these, What will happen on execution of the following code ?, Class base, {, };class derived: protected base, {, };, A. It will not compile as the class body of the base class is not, defined, B. It will not compile as the class body of the derived class is not, defined, C. It will compile successfully, D. The compilation of above code is dependent upon the type of, data provided to it, How many types of inheritance are there, A. 2 B. 3 C. 4 D.5, Suppose class derived is derived from a class Base. Both the classes, contain the Function name display() that take no argument. What, will be the statement in the class derived which will called the, display function of base class, A. display() B. Base:display() C. Base ::display() D. Cannot make, such a call, Suppose class derived is derived from a class Base privately. The, object of class Derived is located in main() can access_______., A. public members of base B. private members of base, C. protected members of base, D. public members of derived, Which is the correct class definition for class C ,Which inherits, from A &B classes, A. Class C:A,B B. Class C::A,B C. Class C:public A,public B, D. Class C::public A,public B, What does the following statement mean?, int (*fp)(char*), , 1, , C, , 1, , A, , 1, , C, , 1, , D, , 1, , C, , 1, , D, , 1, , C, , 1, , C
Page 356 :
18, , 49, 50, , 51, , 52, , 53, , 54, , A. pointer to a pointer, B. pointer to an array of chars, C. pointer to function taking a char* argument and returns an int, D. function taking a char* argument and returning a pointer to int, The operator used for dereferencing or indirection is ____, A. * B. & C. -> D. ->>, Choose the right option, string* x, y;, A. x is a pointer to a string, y is a string, B. y is a pointer to a string, x is a string, C. both x and y are pointer to string types, D. both x and y are string types, #include <iostream>, using namespace std;, int main(), {, int a = 5, b = 10, c = 15;, int *arr[ ] = {&a, &b, &c};, cout <<arr[1];, return 0;, }, A. 10 B. 15 C. 20 D. Random number, The correct statement for a function that takes pointer to a float, a, pointer to a pointer to a char and returns a pointer to a pointer to a, integer is, A. int **fun(float**, char**), B. int *fun(float*, char*), C. int ***fun(float*, char**), D. int ***fun(*float, **char), #include <iostream>, using namespace std;, int main(), {, char arr[20];, int i;, for(i = 0; i < 10; i++), *(arr + i) = 65 + i;, *(arr + i) = '\0';, cout << arr;, return(0);, }, A. ABCDEFGHIJ, B. AAAAAAAAA, C. JJJJJJJJJJJJ, D. None, #include <iostream>, , 1, , A, , 1, , A, , 1, , D, , 1, , C, , 2, , A, , 2, , A
Page 358 :
20, , {, a = 100;, b = 200;, }, friend int compute(sample e1);, , 57, , 58, 59, , };, int compute(sample e1), {, return int(e1.a + e1.b) - 5;, }, int main(), {, sample e;, e.test();, cout << compute(e);, return 0;, }, A. 100 B. 200 C. 295 D. 395, #include <iostream>, using namespace std;, class base, {, int val1, val2;, public:, int get(), {, val1 = 100;, val2 = 300;, }, friend float mean(base ob);, };, float mean(base ob), {, return float(ob.val1 + ob.val2) / 2;, }, int main(), {, base obj;, obj.get();, cout << mean(obj);, return 0;, }, A. 200 B. 150 C. 100 D. 250, To which does the function pointer point to?, A. Function B. Variable C. Constant D. Object, What we will not do with function pointers?, , 2, , A, , 1, , A, , 1, , C
Page 359 :
21, , 60, , 61, , 62, , A. Allocation B. Deallocation C. Both A & B. D. Do Both A &B, #include <iostream>, using namespace std;, int add(int first, int second), {, return first + second + 15;, }, int operation(int first, int second, int (*functocall)(int,, int)), {, return (*functocall)(first, second);, }, int main(), {, int a;, int (*plus)(int, int) = add;, a = operation(15, 10, plus);, cout << a;, return 0;, }, A. 25 B. 36 C. 40 D. 45, #include <iostream>, using namespace std;, void func(int x), {, cout << x ;, }, int main(), {, void (*n)(int);, n = &func;, (*n)( 2 );, n( 2 );, return 0;, }, A. 2 B. 21 C. 22 D. 23, #include <iostream>, using namespace std;, int n(char, int);, int (*p) (char, int) = n;, int main(), {, (*p)('d', 9);, p(10, 9);, return 0;, }, , 2, , C, , 1, , C, , 2, , A
Page 360 :
22, , 63, , 64, , 65, 66, , 67, , int n(char c, int i), {, cout << c << i;, return 0;, }, A. d9 9 B. d9 d9 C. d9 D. Compile time error, #include <iostream>, using namespace std;, int func (int a, int b), {, cout << a;, cout << b;, return 0;, }, int main(void), {, int(*ptr)(char, int);, ptr = func;, func(2, 3);, ptr(2, 3);, return 0;, }, A. 2323 B. 232 C. 23 D. Compiler Error, What is meaning of following declaration?, int(*ptr[5])();, A. ptr is pointer to function., B. ptr is array of pointer to function., C. ptr is pointer to such function which return type is array., D. ptr is pointer to array of function., Void pointer can point to which type of objects?, A. int B> float C. char D. All, What does the following statement mean?, int (*fp)(char*), A. pointer to a pointer B. pointer to an array of chars, C. pointer to function taking a char* argument and returns an int, D. function taking a char* argument and returning a pointer to int, #include <iostream>, using namespace std;, int main(), {, int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};, cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];, return 0;, }, , 2, , D, , 1, , A, , 1, , D, , 1, , C, , 2, , B
Page 361 :
23, , A. 15 18 21 B. 21 21 21 C. 24 24 24 D. Compiler Error, 68, , 69, , 70, , 71, , #include <iostream>, using namespace std;, int main(), {, int arr[] = {4, 5, 6, 7};, int *p = (arr + 1);, cout << *p;, return 0;, }, A. 4 B. 5 C. 6 D. 7, #include <iostream>, using namespace std;, int main(), {, int arr[] = {4, 5, 6, 7};, int *p = (arr + 1);, cout << arr;, return 0;, }, A. 4 B. 5. C. Address of arr D. 6, #include <iostream>, using namespace std;, int main (), {, int numbers[5];, int * p;, p = numbers; *p = 10;, p++; *p = 20;, p = &numbers[2]; *p = 30;, p = numbers + 3; *p = 40;, p = numbers; *(p + 4) = 50;, for (int n = 0; n < 5; n++), cout << numbers[n] << ",";, return 0;, }, A. 10,20,30,40,50 B. 1020304050 C. Compile time error D., Runtime Error, #include <iostream>, using namespace std;, int main(), {, int arr[] = {4, 5, 6, 7};, int *p = (arr + 1);, cout << *arr + 9;, , 2, , B, , 2, , C, , 2, , A, , 2, , C
Page 362 :
24, , return 0;, , 72, , 73, , 74, , 75, , 76, 77, , }, A. 12 B. 5 C. 13 D. Error, A void pointer cannot point to which of these?, A. methods in c++, B. class member in c++, C. all of the mentioned, D. None, #include <iostream>, using namespace std;, int main(), {, int *p;, void *vp;, if (vp == p);, cout << "equal";, return 0;, }, A. equal B. No output C. Error D. Exception, #include <iostream>, using namespace std;, int main(), {, int n = 5;, void *p = &n;, int *pi = static_cast<int*>(p);, cout << *pi << endl;, return 0;, }, A. 5 B. 6 C. Compile Time Error D. Run Time Error, #include <iostream>, using namespace std;, int main(), {, int a = 5, c;, void *p = &a;, double b = 3.14;, p = &b;, c = a + b;, cout << c << '\n' << p;, return 0;, }, A. 8, memory address B. 8.14 C. memory address D. None, What we can’t do on a void pointer?, A. Pointer Arithmetic B. Pointer Functions C. Both D. None, #include <iostream>, , 1, , C, , 1, , A, , 2, , A, , 2, , A, , 1, , A, , 2, , A
Page 363 :
25, , using namespace std;, int main(), {, double arr[] = {5.0, 6.0, 7.0, 8.0};, double *p = (arr+2);, cout << *p << endl;, cout << arr << endl;, cout << *(arr+3) << endl;, cout << *(arr) << endl;, cout << *arr+9 << endl;, return 0;, }, , 78, , 79, , 80, , A. 7, 0xbf99fc98, 8, 5, 14, B. 7, 8, 0xbf99fc98, 5, 14, C. 0xbf99fc98 D. None, #include <iostream>, using namespace std;, class Foo, {, public:, Foo(int i = 0){ _i = i;}, void f(), {, cout << "Executed"<<endl;, }, private:, int _i;, };, int main(), {, Foo *p = 0;, p -> f();, }, A. Executed B. Copiler Error C. Run time Error D. None, A pointer to a base class can point to objects of a derived class., A. TRUE B. FALSE, What does the thispointer point to?, , 2, , A, , 1, , A, , 1, , B
Page 364 :
26, , 81, , 82, , 83, , A. Data member of class B. the object of which the function using, it is a member, C. Member function D. Base class, A pointer is, A. the address of a variable. B. an indication of the variable to be, accessed next. C. a variable for storing addresses., D. the data type of an address variable., The expression *test can be said to, A. refer to the contents of test. B. dereference test., C. refer to the value of the variable pointed to by test. D. All of the, above, Definition for an array arrof 8 pointers that point to variables of, type float is, A. *float arr[8] B. float* arr[8]; C. float pointer[8] D. int *ary[8], , 1, , C, , 1, , D, , 1, , B
Page 365 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 1, Every class has at least one constructor function, even when none is declared., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 2, Can constructors be overloaded?, TRUE, FALSE, , Id, Question, A, B, , 3, What is the difference between struct and class in terms of Access Modifier?, By default all the struct members are private while by default class members are public., By default all the struct members are protected while by default class members are, private., By default all the struct members are public while by default class members are private., By default all the struct members are public while by default class members are protected., C, 1, I, , C, D, Answer, Marks, Unit, , Id, Question, A, B, C, D, Answer, , A, 1, I, , A, 1, I, , 4, An abstract class can be instantiated., TRUE, FALSE, , B
Page 366 :
Marks, Unit, , 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 5, The default access level assigned to members of a class is ______, Private, Public, Protected, Needs to be assigned, A, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 6, There is nothing like a virtual constructor of a class., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 7, Which of the following operators allow defining the member functions of a class outside, the class?, ::, ?, :?, %, A, 1, I, , Id, Question, A, B, C, D, Answer, , 8, Which type of class has only one unique value for all the objects of that same class?, This, Friend, Static, Both a and b, C, , B, 1, I
Page 367 :
Marks, Unit, , 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 9, Which one of the following is not a fundamental data type in C++?, Float, string, Int, Char, B, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 10, What is a constructor?, A class automatically called whenever a new object of this class is created., A class automatically called whenever a new object of this class is destroyed., A function automatically called whenever a new object of this class is created., A function automatically called whenever a new object of this class is destroyed., C, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 11, Under what conditions a destructor destroys an object?, Scope of existence has finished, Object dynamically assigned and it is released using the operator delete., Program terminated., Both a and b., D, 1, I, , Id, Question, , 12, If a member needs to have unique value for all the objects of that same class, declare the, member as, Global variable outside class, , A
Page 368 :
B, C, D, Answer, Marks, Unit, , Local variable inside constructor, Static variable inside class, Dynamic variable inside class, B, 1, I, , Id, Question, , 13, If a member needs to have unique value for all the objects of that same class, declare the, member as, Global variable outside class, Local variable inside constructor, Static variable inside class, Dynamic variable inside class, B, 1, I, , A, B, C, D, Answer, Marks, Unit, , A, B, C, D, Answer, Marks, Unit, , 14, When class B is inherited from class A, what is the order in which the constructers of, those classes are called, Class A first Class B next, Class B first Class A next, Class B's only as it is the child class, Class A's only as it is the parent class, A, 1, I, , Id, , 15, , Id, Question
Page 369 :
Question, A, B, C, D, Answer, Marks, Unit, , Which one of the following is not a valid reserved keyword in C++?, Explicit, Public, Implicit, Private, C, 1, I, , Id, Question, , 16, Variables declared in the body of a particular member function are known as data, members and can be used in all member functions of the class., TRUE, FALSE, , A, B, C, D, Answer, Marks, Unit, , B, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 17, In a class definition, data or functions designated private are accessible, to any function in the program., only if you know the password., to member functions of that class., only to public members of the class., C, 1, I, , Id, Question, A, , 18, A member function can always access the data, in the object of which it is a member.
Page 370 :
B, C, D, Answer, Marks, Unit, , in the class of which it is a member., in any object of the class of which it is a member., in the public part of its class., A, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 19, Classes are useful because they, can closely model objects in the real world., permit data to be hidden from other classes., bring together all aspects of an entity in one place., Options A, B and C, D, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 20, For the object for which it was called, a const member function, can modify both const and non-const member data., can modify only const member data., can modify only non-const member data., can modify neither const nor non-const member data., D, 1, I, , Id, Question, A, B, C, , 21, Dividing a program into functions, is the key to object-oriented programming., makes the program easier to conceptualize., may reduce the size of the program.
Page 371 :
D, Answer, Marks, Unit, , Option B and C, D, 2, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 22, An expression, usually evaluates to a numerical value., may be part of a statement., always occurs outside a function., Option A and B, D, 2, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 23, A variable of type char can hold the value 301., TRUE, FALSE, , Id, Question, , 24, In an assignment statement, the value on the left of the equal sign is always equal to the, value on the right., TRUE, FALSE, , A, B, , B, 1, I
Page 372 :
C, D, Answer, Marks, Unit, , Id, Question, A, B, C, D, Answer, Marks, Unit, , B, 1, I, , 25, It’s perfectly all right to use variables of different data types in the same arithmetic, expression., TRUE, FALSE, , A, 1, I, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 26, A function’s single most important role is to, give a name to a block of code., reduce program size., accept arguments and provide a return value., help organize a program into conceptual units., D, 1, I, , Id, Question, , 27, A function argument is
Page 373 :
A, B, C, D, Answer, Marks, Unit, , a variable in the function that receives a value from the calling program., a way that functions resist accepting the calling program’s values., a value sent to the function by the calling program., a value returned by the function to the calling program., C, 1, I, , Id, Question, , 28, When arguments are passed by value, the function works with the original arguments in, the calling program., TRUE, FALSE, , A, B, C, D, Answer, Marks, Unit, , B, 1, I
Page 374 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 29, Which of the following can legitimately be passed to a function?, A constant, A variable, A structure, All of the above, D, 1, I
Page 375 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 30, How many values can be returned from a function?, 0, 1, 2, 3, B, 1, I
Page 376 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 31, When a function returns a value, the entire function call can appear on the right side of the, equal sign and be assigned to another variable., TRUE, FALSE, , A, 1, I
Page 377 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 32, When an argument is passed by reference, a variable is created in the function to hold the argument’s value., the function cannot access the argument’s value., a temporary variable is created in the calling program to hold the argument’s value., the function accesses the argument’s original value in the calling program., D, 1, I
Page 378 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 33, Overloaded functions, are a group of functions with the same name., all have the same number and types of arguments., make life simpler for programmers., A and C, D, 2, I
Page 379 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 34, A default argument has a value that, may be supplied by the calling program., may be supplied by the function., must have a constant value., A and B, 1, 1, I
Page 380 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 35, A static local variable is used to, make a variable visible to several functions., make a variable visible to only one function., retain a value when a function is not executing., B and C, D, 2, I
Page 381 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 36, In C++ there can be an array of four dimensions., TRUE, FALSE, , A, 1, I
Page 382 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 37, When an array name is passed to a function, the function, accesses exactly the same array as the calling program., refers to the array using a different name than that used by the calling program., refers to the array using the same name as that used by the calling program., A and B, D, 1, I
Page 383 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 38, The compiler will complain if you try to access array element 14 in a 10-element array., TRUE, FALSE, , B, 1, I
Page 384 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 39, The extraction operator (>>) stops reading a string when it encounters a space., TRUE, FALSE, , A, 1, I
Page 385 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 40, You can read input that consists of multiple lines of text using, the normal cout <<combination., the cin.get() function with one argument., the cin.get() function with two arguments., the cin.get() function with three arguments., D, 1, I
Page 386 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 41, You should prefer C-strings to the Standard C++ string class in new programs., TRUE, FALSE, , B, 1, I
Page 387 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 42, Objects of the string class, are zero-terminated., can be copied with the assignment operator., do not require memory management., Both B and C, D, 1, I
Page 388 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 43, Can destuctors be private in C++?, Yes, No, , A, 1, I
Page 389 :
Id, Question, , 44, , A, B, C, D, Answer, Marks, Unit, , 28, 32, 20, 24, C, 1, I, , What is value of size?
Page 390 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 45, , What value will be printed for data.i?, 10 220.5 230.5 Unpredictable Value, 220, 230.5, Unpredictable Value, D, 1, I
Page 391 :
Id, Question, , 46, , A, B, C, D, Answer, Marks, Unit, , 25, 30, 9, 3, B, 1, I, , Id, , 47
Page 392 :
Question, , A, B, C, D, Answer, Marks, Unit, , 1, 3, 4, 6, A, 1, I, , Id, , 48
Page 393 :
Question, , What is the compilation error for this, program?, A, B, C, D, Answer, Marks, Unit, , Each undeclared identifier is reported only once, cout and cin not declared in scope, invalid conversion from int to float, All of the above, B, 2, I, , Id, , 49
Page 394 :
Question, , A, B, C, D, Answer, Marks, Unit, , 45, 55, Array Sum: 45, Will not compile, D, 2, I, , Id, , 50
Page 395 :
Question, , A, B, C, D, Answer, Marks, Unit, , 5, 20, 15, Unpredictable value, B, 1, I, , Id, , 51
Page 396 :
Question, , A, B, C, D, Answer, Marks, Unit, , only 2, only 1, both 1 &2, None of the above, B, 2, I, , Id, , 52
Page 397 :
Question, , A, B, C, D, Answer, Marks, Unit, , call-2, call-1, call-3, call-1, call-2, B, 1, I, , Id, , 53
Page 398 :
Question, , What will be the output of the program?, A, B, C, D, Answer, Marks, Unit, , 1, Default value, Will not compile, None of the above, C, 1, I
Page 399 :
Id, Question, , 54, , What is the output of the program?, A, B, C, D, Answer, Marks, Unit, , 00, x=0y=0, 0, Compilation error, D, 1, I
Page 400 :
Id, Question, , 55, , Which function will change the state of the object?, A, B, C, D, Answer, Marks, Unit, , Only set(), Only display(), display() and set() both, None of the above, A, 2, I
Page 401 :
Id, Question, , 56, What will be the output of the following program?, , A, B, C, D, Answer, Marks, Unit, , Compilation Error: display() cannot be accessed in application, Compilation Error:Test class object cannot be accessed in function Demo, Compilation Error: Variable x is private in Test, Both A and B, C, 2, I, , Id, Question, A, , 57, The only integer that can be assigned directly to a pointer is _________, 0
Page 402 :
B, C, D, Answer, Marks, Unit, , -1, 999, -999, A, 1, I, , Id, Question, A, , 58, Which of the following feature is not supported by C++?, Exception Handling
Page 403 :
B, C, D, Answer, Marks, Unit, , Reflection, Operator Overloading, Namespace, B, 1, I, , Id, Question, , 59, Suppose aand bare integer variables and we form the sum a + b. Now suppose cand
Page 404 :
A, B, C, D, Answer, Marks, Unit, , dare floating-point variables and we form the sum c + d.The two +operators here are, clearly being used for different purposes. This is an example of ____________, Operator Overloading, Inheritance, Function Overloading, Constructor, A, 1, I, , Id, Question, A, B, C, , 60, The operators that cannot be overloaded is, *, ::
Page 405 :
D, Answer, Marks, Unit, , (), C, 1, I, , Id, Question, , 61, Empty parentheses following a function name in a function prototype indicate that the, function does not require any parameters to perform its task., TRUE, FALSE, , A, B, C, D, Answer, , A
Page 406 :
Marks, Unit, , 1, I, , Id, Question, , 62, C++ programmers concentrate on creating , which contain data members and the member, functions that manipulate those data members and provide services to clients., Structures, Classes, Objects, Function, B, , A, B, C, D, Answer
Page 407 :
Marks, Unit, , 1, I, , Id, Question, A, B, , 63, Which of the following is FALSE about references in C++, A reference must be initialized when declared, Once a reference is created, it cannot be later made to reference another object; it cannot, be reset, References cannot be NULL, References cannot refer to constant value, D, , C, D, Answer
Page 408 :
Marks, Unit, , 1, I, , Id, Question, , 64, What will be the output of following program?, #include <iostream>, using namespace std;, class Test
Page 409 :
{, public:, Test() { cout <<"Hello from Test() "; }, } a;, , A, B, C, D, Answer, Marks, Unit, , Id, Question, , A, B, , int main(), {, cout <<"Main Started ";, return 0;, }, Main Started, Main Started Hello from Test(), Hello from Test() Main Started, Compiler Error: Global objects are not allowed, C, 2, I, , 65, Which of the following is true about constructors., They cannot be virtual., They cannot be private., They are automatically called by new operator, All 1, 2, and 3, Only 1 and 3
Page 410 :
C, D, Answer, Marks, Unit, , Only 1 and 2, Only 2 and 3, B, 1, I, , Id, Question, , 66, Which of the following operators are overloaded by default by the compiler?, 1) Comparison Operator ( == ), 2) Assignment Operator ( = ), Both 1 and 2, Only 1, Only 2, None of the two, C, 1, I, , A, B, C, D, Answer, Marks, Unit
Page 411 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 67, Which of the following is true about inline functions and macros., Inline functions do type checking for parameters, macros don't, Macros cannot have return statement, inline functions can, Macros are processed by pre-processor and inline functions are processed in later stages, of compilation., All of the above, D, 1, I
Page 412 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 68, In C++, const qualifier can be applied to, Member functions of a class, Function arguments, To a class data member which is declared as static, Reference variables, Only 1, 2 and 3, Only 1, 2 and 4, All, Only 1, 3 and 4, C, 1, I
Page 413 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 69, In C++ ..................... operator is used for Dynamic memory allocation., Scope resolution, Conditional, New, Membership access, C, 1M, I
Page 415 :
A, B, C, D, Answer, Marks, Unit, , Id, Question, A, B, C, D, Answer, Marks, Unit, , Print natural numbers 0 to 99, Print natural numbers 1 to 99, Print natural numbers 0 to 100, Print natural numbers 1 to 100, D, 2M, I, , 71, Because the lifetime of a local variable is limited and determined automatically, these, variables are also called, Automator, Automatic, Dynamic, Static, B, 1M, I
Page 416 :
Id, Question, , 72, Which of the following header file includes definition of cin and cout?, , A, B, C, D, Answer, Marks, Unit, , istream.h, ostream.h, iomanip.h, iostream.h, D, 1, I
Page 417 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 73, Which of the following statements regarding inline functions is correct?, It speeds up execution, It slows down execution, It increases the code size, Both A and C., D, 1, I
Page 418 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 74, Which of the following access specifier is used as a default in a class definition?, Public, Private, Protected, Friend, B, 1, I
Page 419 :
Id, Question, , 75, Which of the following statements is correct in C++?, , A, B, C, D, Answer, Marks, Unit, , Classes cannot have data as protected members., Structures can have functions as members., Class members are public by default., Structure members are private by default., B, 1, I
Page 420 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 76, cout is a/an __________, operator, Function, object, Macro, C, 1, I
Page 421 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 77, Which of the following concepts of OOPS means exposing only necessary, information to client?, Encapsulation, Abstraction, Data hiding, Data binding, C, 1, 1
Page 422 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 78, Which of the following keywords is used to control access to a class member?, Default, Break, Protected, Asm, C, 1, 1
Page 423 :
Id, Question, A, , 79, Utility functions are also called as ......., Virtual function, , B, , Friend function, , C, , Helper function, , D, , None of above, , Answer, Marks, Unit, , C, 1, 1
Page 424 :
Id, Question, , 80, ......... is a member function with the same name as the class., , A, , Friend function, , B, , Constructor, , C, , Destructor, , D, , None of above, , Answer, , B, , Marks, Unit, , 1, 1
Page 425 :
Id, Question, , 81, Which is not the feature of constructor?, , A, , It cannot be inherited., , B, , It should be declared in Private., , C, , It do not have return type, , D, , All of above, , Answer, , B, , Marks, Unit, , 1, 1
Page 426 :
Id, Question, , 82, Which is not type of constructor?, , A, , Default, , B, , Copy, , C, , Parameterized, , D, , None of above, , Answer, , D, , Marks, Unit, , 1, 1
Page 427 :
Id, Question, , 83, Objects are destroyed in the reverse order of its creation., , A, , True, , B, , False, , C, , -, , D, , -, , Answer, , A, , Marks, Unit, , 1, 1
Page 428 :
Id, Question, , 84, .... constructor is used for copying the object of same class type., , A, , Copy, , B, , Default, , C, , Parameterized, , D, , None of above, , Answer, , A, , Marks, Unit, , 1, 1
Page 429 :
Id, Question, , 85, The function inside a class is called as ......., , A, , Class Function, , B, , Member Function, , C, , Method, , D, , All of above, , Answer, , B, , Marks, Unit, , 1, 1
Page 430 :
Id, Question, , 86, Which operator is used to define member function of a class outside the class?, , A, , !, , B, , :, , C, , ::, , D, , ., , Answer, , C, , Marks, Unit, , 1, 1
Page 431 :
Id, Question, , 87, How many objects can be created by a class?, , A, , 1, , B, , 2, , C, , 3, , D, , As Many as required, , Answer, , D, , Marks, Unit, , 1, 1
Page 432 :
Id, Question, , 88, Default return type of C++ main( ) is ....., , A, , float, , B, , void, , C, , Int, , D, , Pointer, , Answer, , C, , Marks, Unit, , 1, 1
Page 433 :
Id, Question, , 89, Enumerated data type is ........, , A, , User-defined data type, , B, , In-built data type, , C, , Derived data type, , D, , None of above, , Answer, , A, , Marks, Unit, , 1, 1
Page 434 :
Id, Question, , 90, Attributes of a class are called as ........, , A, , Member functions, , B, , Data members, , C, , Objects, , D, , All of above, , Answer, , B, , Marks, Unit, , 1, 1
Page 435 :
Id, Question, , 91, Class acquire space in memory., , A, , True, , B, , False, , C, , -, , D, , -, , Answer, , B, , Marks, Unit, , 1, 1
Page 436 :
Id, Question, , 92, In object-oriented programming ........ is more important., , A, , Function, , B, , Procedure, , C, , Data, , D, , All of above, , Answer, , C, , Marks, Unit, , 1, 1
Page 437 :
Id, Question, , 93, Object-oriented programming follows Top-down approach., , A, , True, , B, , False, , C, , -, , D, , -, , Answer, , B, , Marks, Unit, , 1, 1
Page 438 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 94, The following operators can not be overloaded, Unary operator, Binary operator, Ternary operator, None of the above, C, 1, 1
Page 439 :
Id, Question, , 95, , A, B, C, D, Answer, Marks, Unit, , Multilevel inheritance, Hierarchical inheritance, Hybrid inheritance, None of the above, D, 1, 1, , C++ does not supports the following
Page 440 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 96, Which of the following is not the keyword in C++?, Volatile, Friend, Extends, This, C, 1, 1
Page 441 :
Id, Question, A, B, C, D, , 97, Which data type can be used to hold a wide character in C++?, unsigned char;, Int, wchar_t, None of the above, , Answer, Marks, Unit, , C, 1, 1
Page 442 :
Id, Question, , 98, Which type is best suited to represent the logical values?, , A, B, C, D, Answer, Marks, Unit, , integer, boolean, character, all of the mentioned, B, 1, 1
Page 443 :
Id, Question, , 99, The following is the C++ style comment, , A, B, C, D, Answer, Marks, Unit, , //, /*..*/, –, None of above, A, 1, 1
Page 444 :
Id, Question, , 100, Which of the following statements is false?, , A, B, C, D, Answer, Marks, Unit, , Every C++ program must have a main()., In C++, white spaces and carriage returns are ignored by the compiler., C++ statements terminate with semicolon., Main() terminates with semicolon., D, 1, 1
Page 445 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , Id, Question, , 101, Which of the following statements regarding comments is false?, /*..*/, Comment beginning with // extends to the end of the line, Comments may be nested, Comments are used to describe a program, C, 1, 1, , 102, The result of the following statement is
Page 446 :
int y = 7;, int ans = ++y;, cout<<”ans=”<<ans;, cout<<”y”<<y;, A, B, C, D, Answer, Marks, Unit, , ans=7, y=7, ans=8,y=7, ans=8,y=8;, None, C, 1, 1, , Id, Question, , 103, Inline functions are
Page 447 :
A, B, C, D, Answer, Marks, Unit, , Id, Question, A, , Declared in the class defined outside the class, Defined outside the class using keyword inline, Defined inside the class using keyword inline, None of the above, B, 1, 1, , 104, Functions can returns, Arrays
Page 448 :
B, C, D, Answer, Marks, Unit, , References, Objects, All of above, D, 1, 1, , Id, Question, , 105, Which of the following control expressions are valid for an if statement?, , A, , an integer expression
Page 449 :
B, C, D, Answer, Marks, Unit, , Id, Question, , a Boolean expression, either A or B, Neither A nor B, C, 1, 1, , 106, State true of false., i) We cannot make the function inline by defining a function outside the class., ii) A member function can be called by using its name inside another member, function of the same class, this is known as nesting of member function.
Page 450 :
A, B, C, D, Answer, Marks, Unit, , Id, Question, , True, True, True, False, False, True, False, False, C, 1, 1, , 107, What will be the values of x, m and n after execution of the following statements?, Int x, m, n;, m=10;, n=15;, x= ++m + n++;
Page 451 :
A, B, C, D, Answer, Marks, Unit, , x=25, m=10, n=15, x=27, m=10, n=15, x=26, m=11, n=16, x=27, m=11, n=16, C, 2, 1, , Id, Question, , 108, How many types of polymorphisms are supported by C++?, , A, B, C, D, , 1, 2, 3, 4
Page 452 :
Answer, Marks, Unit, , B, 1, 1, , Id, Question, , 109, Which of the following approach is adapted by C++?, , A, B, C, D, Answer, Marks, , Top-down, Bottom-up, Right-left, Left-right, B, 1
Page 453 :
Unit, , 1, , Id, Question, , 110, Which of the following is the correct class of the object cout?, , A, B, , Iostream, istream, , C, D, Answer, Marks, , Ostream, Ifstream, C, 1
Page 454 :
Unit, , 1, , Id, Question, , 111, Which of the following functions are performed by a constructor?, , A, B, , Construct a new class, Construct a new object, , C, D, , Construct a new function, Initialize objects, , Answer, Marks, , D, 1
Page 455 :
Unit, , 1, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 112, Which of the following ways are legal to access a class data member using this pointer?, this->x, this.x, *this.x, *this-x, A, 1, 1
Page 456 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 113, Which operator is having right to left associativity in the following?, Array subscripting, Function call, Addition and subtraction, Type cast, D, 1, 1
Page 457 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 114, Which operator is having the highest precedence?, Postfix, Unary, Shift, Equality, A, 1, 1
Page 458 :
Id, Question, , 115, , A, B, C, , 35, 20, 25, , #include <iostream>, using namespace std;, int main(), {, int a;, a = 5 + 3 * 5;, cout <<a;, return 0;, }
Page 459 :
D, Answer, Marks, Unit, , 30, B, 2, 1, , Id, Question, , 116, , A, , 20 10, , #include <iostream>, using namespace std;, main(), {, double a = 21.09399;, float b = 10.20;, int c ,d;, c = (int) a;, d = (int) b;, cout <<c <<' '<<d;, return 0;, }
Page 460 :
B, C, D, Answer, Marks, Unit, , 10 21, 21 10, None, A, 2, 1, , Id, Question, , 117, , A, B, C, D, Answer, , 2, 4, 8, Garbage, B, , #include <iostream>, using namespace std;, int main(), {, int num1 = 10;, float num2 = 20;, cout <<sizeof(num1 + num2);, return 0;, }
Page 461 :
Marks, Unit, , Id, Question, , 2, 1, , 118, #include <stdio.h>, using namespace std;, int array1[] = {1200, 200, 2300, 1230, 1543};, int array2[] = {12, 14, 16, 18, 20};, int temp, result = 0;, int main(), {, for (temp = 0; temp <5; temp++) {, result += array1[temp];, }, for (temp = 0; temp <4; temp++) {, result += array2[temp];, }, cout <<result;, return 0;, }
Page 462 :
A, B, C, D, Answer, Marks, Unit, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 6553, 6533, 6522, 12200, B, 2, 1, , 119, In procedural programming the focus in on …..........., data, structure, function, pointers, C, 1, 1
Page 463 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 120, In object oriented programming the focus is on …......., data, structure, function, pointers, A, 1, 1
Page 464 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 121, Which of the following feature of procedure oriented program is false?, Makes use of bottom up approach, Functions share global data, The most fundamental unit of program is function, All of these, A, 1, 1
Page 465 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 122, Which of the following feature of object oriented program is false?, Data and Functions can be added easily, Data can be hidden from outside world, Object can communicate with each other, The focus is on procedures, D, 1, 1
Page 466 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 123, C++ was originally developed by …......., Donald Knuth, Bjarne Sroustrups, Dennis Ritchie, None of these, B, 1, 1
Page 467 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 124, Which of the following approach is adopted in C++?, Top down, Bottom up, Horizontal, Vertical, B, 1, 1
Page 468 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 125, Which feature of C++ contain the concept of super class and subclass?, Class and object, Encapsulation, Abstraction, Inheritance, D, 1, 1
Page 469 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 126, The main intention of using inheritance is …........., to help in converting one data type to other, to hide the details of base class, to extend the capabilities of base class, to help in modular programming, C, 1, 1
Page 470 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 127, If particular software can be used in some other application than the one, for which it is created then it reveals …........., data binding, data reusability, data encapsulation, none of these, B, 1, 1
Page 471 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 128, Which of the following data type does not return anything?, Int, short, long, void, D, 1, 1
Page 472 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 129, How many objects can be created from an abstract class?, Zero, One, Two, As many as we want, A, 1, 1
Page 473 :
Id, Question, , 130, Which of the following statements is correct for a static member function?, 1. It can access only other static members of its class., , , A, B, C, D, Answer, Marks, Unit, , It can be called using the class name, instead of objects, , Only 1 is correct, Only 2 is correct, Both 1 and 2 are correct, Both 1 and 2 are incorrect, C, 1, 1
Page 474 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 131, Select the correct statement, I. In procedural programming oriented language all the function calls are, resolved at compile time., II. In object oriented programming language all function calls are, resolved at compile time., Only I, Only II, Both I and II, Neither I nor II, A, 1, 1
Page 475 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 132, What happens when a class with parameterized constructors and having no default, constructor is used in a program and we create an object that needs a zero-argument, constructor?, Compile-time error, Preprocessing error, Runtime error, Runtime exception, A, 1, 1
Page 476 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 133, Which of the following interface determines how your program will be used by other, program?, Public, Private, Protected, None of these, A, 1, I
Page 477 :
Id, Question, A, B, , 134, What is the difference between struct and class in C++?, All members of a structure are public and structures don't have constructors and destructors, Members of a class are private by default and members of struct are public by default., When deriving a struct from a class/struct, default access-specifier for a base class/struct, is public and when deriving a class, default access specifier is private., , C, , All members of a structure are public and structures don't have virtual functions, , D, Answer, Marks, Unit, , All above, B, 1, I
Page 478 :
Id, Question, , 135, Predict the output of following C++ program, #include<iostream>, using namespace std;, class Empty {};, , A, B, C, D, Answer, Marks, Unit, , int main(), {, cout <<sizeof(Empty);, return 0;, }, A non zero value, 0, Compile time error, Runtime error, A, 1, I
Page 479 :
Id, Question, , 136, class Test {, int x;, };, int main(), {, Test t;, cout <<t.x;, return 0;, }, , A, B, C, D, Answer, Marks, Unit, , 0, Garbage value, Compile time error, C, 1, I
Page 480 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 137, Which of the following is true?, All objects of a class share all data members of class, Objects of a class do not share non-static members. Every object has its own copy, Objects of a class do not share codes of non-static methods, they have their own copy, None, B, 1, I
Page 481 :
Id, Question, , 138, Assume that an integer and a pointer each takes 4 bytes. Also, assume that there is no, alignment in objects. Predict the output following program., #include<iostream>, using namespace std;, class Test, {, static int x;, int *ptr;, int y;, };, , A, B, C, D, Answer, Marks, Unit, , int main(), {, Test t;, cout <<sizeof(t) <<" ";, cout <<sizeof(Test *);, }, 12 4, 12 12, 84, 88, 2, I
Page 482 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 139, Which of the following is true about the following program, #include <iostream>, class Test, {, public:, int i;, void get();, };, void Test::get(), {, std::cout <<"Enter the value of i: ";, std::cin >>i;, }, Test t; // Global object, int main(), {, Test t; // local object, t.get();, std::cout <<"value of i in local t: "<<t.i<<'\n';, ::t.get();, std::cout <<"value of i in global t: "<<::t.i<<'\n';, return 0;, }, Compiler Error: Cannot have two objects with same class name, Compiler Error in Line "::t.get();", Compiles and runs fine, C, 2, I
Page 483 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 140, How to create a dynamic array of pointers (to integers) of size 10 using new in C++?, Hint: We can create a non-dynamic array using int *arr[10], int *arr = new int *[10];, int **arr = new int *[10];, int *arr = new int [10];, Not possible, 1, 1, I
Page 484 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 141, Which of the following is true about new when compared with malloc. 1) new is an, operator, malloc is a function 2) new calls constructor, malloc doesn't 3) new returns, appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate, type., 1 and 3, 2 and 3, 1 and 2, All 1,2,3, C, 1, I
Page 485 :
Id, Question, , 142, Predict the output?, #include <iostream>, using namespace std;, class Test, {, int x;, Test() { x = 5;}, };, , A, B, C, D, Answer, Marks, Unit, , int main(), {, Test *t = new Test;, cout <<t->x;, }, Compile time error, Garbage, 0, 5, A, 2, I
Page 486 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 143, What happens when delete is used for a NULL pointer?, int *ptr = NULL;, delete ptr;, Compile time error, Run time error, No effect, C, 1, I
Page 487 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 144, Is it fine to call delete twice for a pointer?, #include<iostream>, using namespace std;, int main(), {, int *ptr = new int;, delete ptr;, delete ptr;, return 0;, }, Yes, No, , B, 1, I
Page 488 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 145, Which of the followings is/are automatically added to every class, if we do not write our, own., Copy constructor, Assignment operator, A constructor without any parameter, All, D, 1, I
Page 489 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 146, When a copy constructor may be called?, When an object of the class is returned by value, When an object of the class is passed (to a function) by value as an argument, When an object is constructed based on another object of the same class, All, D, 1, I
Page 490 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, , 147, Output of following program?, #include<iostream>, using namespace std;, class Point {, Point() { cout <<"Constructor called"; }, };, int main(), {, Point t1;, return 0;, }, Compile time error, Run time error, Constructor called, A, 1, I
Page 491 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 148, Which of the following interface determines how your program will be used by other, program?, Public, Private, Protected, None of these, A, 1, I
Page 492 :
Id, Question, , 149, #include<iostream>, using namespace std;, class Point {, public:, Point() { cout <<"Constructor called"; }, };, int main(), {, Point t1, *t2;, return 0;, }, , A, B, C, D, Answer, Marks, Unit, , Compiler Error, Constructor called, Constructor called, Constructor called, C, 1, I
Page 493 :
Id, Question, , 150, #include<iostream>, using namespace std;, class X, {, public:, int x;, };, int main(), {, X a = {10};, X b = a;, cout <<a.x <<" " <<b.x;, return 0;, }, , A, B, C, D, Answer, Marks, Unit, , Compiler Error, 10 followed by Garbage Value, 10 10, 10 0, D, 1, I
Page 494 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 1, Polymorphism is supported by the c++ by using following ways, function overloading, operator overloading, virtual functions, all of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 2, Compile time polymorphism is supported by, function overloading, virtual function, operator overloading, both a&c, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 3, Run time polymorphism is supported by, function overloading, operator overloading, virtual function, both a and b, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 4, Selecting the appropriate overloaded function by the compiler is known as, late binding, early binding, both a and b, none of the above, B, 1, II, , Id, Question, A, B, , 5, object to function binding is done at compile time then is it known as, early binding, compile time binding
Page 495 :
C, D, Answer, Marks, Unit, , none of the above, both a and b, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 6, Run time polymorphism is done by using, function overloading, operator overloading, virtual function, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 7, Operator overloading is ---., run time polymorphism, compile time polymorphism, none of the above, both a and b, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 8, Which of the following operator cannot be overloaded, scope resolution operator(::), Size of operator (sizeof[]), Conditional operator(?:), All of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 9, Which of the operator cannot be overloaded, >=, &, <=, ::, D, 1, II
Page 496 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 10, While performing operator overloading which function/keyword we have to use, Function, Operator, Op, none of the above, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 11, Which of the statement is not true about operator overloading, we can overload only existing operator, basic meaning cannot be changed, binary operator should have return type, All of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 12, Pick up the correct statement related with operator overloading, we can overload a class access operator, we can change the meaning of basic operator, binary operator should have a return type, both a and b, C, 1, II, , Id, Question, , 13, We are overloading a unary operator without friend function how many argument we have, to pass, 1, 2, 0, none of the above, C, 1, II, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, , 14, Suppose we are overloading a binary operator with friend function, how many parameter, of argument we have to pass, 1, 2
Page 497 :
C, D, Answer, Marks, Unit, , 3, none of ths above, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 15, we are overloading a binary operator without friend function how many argument we, have to pass, 1, 2, 0, none of the abve, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 16, What is polymorphism, it is ability to take many forms, it is instance of class, one class acquire the properties of another class, All of the above, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 17, What is true about the operator overloading, with friend function we need to pass two arguments for binary operator, with friend function we need to pass one arguments for unary operator, both a and b, none of the above, C, 1, II, , Id, Question, , 18, ______allows you to give special meaning to some operator when there are operands, associated with it., function overloading, virtual function, operator overloading, none of the above, C, 1, , A, B, C, D, Answer, Marks
Page 498 :
Unit, , II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 19, Converting from small to larger data type is known as ____., promotion, operator, polymorphism, none of the above, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 20, what are the types of type conversion, implicit, explicit, both a and b, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 21, Reusability is supported by following feature, polymorphisms, message passing, inheritance, operator overloading, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 22, Deriving a new class from a base class is known as __., polymorphisms, inheritance, message passing, operator overloading, B, 1, II, , Id, Question, A, B, , 23, Base class is also known as___., super class, parent class
Page 499 :
C, D, Answer, Marks, Unit, , both a and b, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 24, Child class is also known as, sub class, derived class, both a and b, known class, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 25, Derived class___ cannot access from base class, constructor, destructors, copy constructor, all of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 26, we can derive a new class from a derived class, true, false, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 27, How many parameter does a conversion operator take?, 0, 2, 3, as many as possible, A, 1, II, , A, 1, II
Page 500 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 28, __is used to define pure virtual function?, &, =0, @, *, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 29, Which is also known as abstract class?, virtual function, pure virtual function, derived class function, base class function, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 30, pick the correct option, We can make the instance of the abstract class, We can not make the instance of the abstract class, both a and b, none of the above, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 31, How many access specifiers are there in c++?, 2, 3, 5, 4, B, 1, II, , Id, Question, A, B, C, D, , 32, Where we have to use an abstract class?, in base class only, in derived class only, both and b, None of the above
Page 501 :
Answer, Marks, Unit, , A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 33, For what we can apply access, function, data member, none of the above specifier, both a and c, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 34, What is default access specifier for class?, public, protected, private, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 35, We have to define a constructor for the derived class must be required____., if base class constructor does not require arguments, if base/parent class constructor required arguments, no need, always, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 36, Use of the friend function is___., the class allowing access to another class, the private section of a class, the public section of the class, all of the above, D, 1, II, , Id, Question, , 37, If an attribute is private define then which method can have access to it
Page 502 :
A, B, C, D, Answer, Marks, Unit, , only static function, only functions of that class, only method in that package, none of the above, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 38, What is syntax of deriving a new class from base class is___., class name, new class name, new class name, base class name, class name: access specifier class name, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 39, Which constructor will initialize the base class data member, base class, derived class, derived derived class, none of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 40, Inheritance can be done using :: symbol, True, False, , Id, Question, , 41, When we derived a new class using more than one class then type of inheritance is known, as____., multiple inheritance, single inheritance, hybrid inheritance, , A, B, C, , B, 1, II
Page 503 :
D, Answer, Marks, Unit, , multilevel inheritance, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 42, When class B is derive from A , and class C is derived from B, this kind of inheritance is, known as ______., multiple inheritance, single inheritance, hybrid inheritance, multilevel inheritance, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 43, The base class will provide you__________., specific objects than the derived class, more generalized version of derived class, empty template of base class, all of the above, B, 1, II, , Id, Question, , 44, Pick up the correct statement form following, i)we have to use abstract keyword to define the abstract class, ii)inheritance allows multilevel class hierarchies more than two levels also, iii)reusability is supported by derivation, iv) we can change the meaning of operator during operator overloading, i only, ii only, i and ii only, ii and iii only, D, 2, II, , A, B, C, D, Answer, Marks, Unit, Id, Question, , 45, What does derived class does not inherit from the base class, i)constructor, ii)destructor, iii)operator=(), iv)friends
Page 504 :
A, B, C, D, Answer, Marks, Unit, , i and ii, ii and iii, only i, iii and iv, all of the above, D, 1, II, , Id, Question, , A, B, C, D, Answer, Marks, Unit, , 46, Choose the correct the statement from following, i)inheritance supported in terms of single, multiple , multilevel ,hybrid inheritance, ii) polymorphisms is supported by function overloading , operator overloading and, virtual function, iii) abstraction is not supported by c++, i is correct, only ii is correct, i and ii is correct, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 47, _____types of classes in c++., 1, 2, 3, 4, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 48, :_______is used to define a pure virtual function., $, ^, =0, #, C, 1, II, , Id, Question, A, B, , 49, Pick up the correct statement, a base class may have more than one class, derived class can be derived from more than one class
Page 505 :
C, D, Answer, Marks, Unit, , both a and b, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 50, class A: public B, public C is a type of inheritance, Single, Multiple, Multilevel, Hybrid, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 51, When we have to use the mutable keyword, data member to change within a const member function, not allow the data member to change within a const member function, it will copy the values of the variable, none of the above mentioned, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 52, choose the correct statement, destructor cannot be inherited, private member not inherited to derived class, constructor cannot inherited, a and c, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 53, Use of function or operator to act different ways on different data type is called as, derivation, inheritance, polymorphisms, none of the above, C, 1, II
Page 506 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 54, Choose the correct statement, Constructor has a return type, constructor always define in public scope, constructor has same name that of class name, b and c, D, 1, II, , Id, Question, , 55, overloading of a prefix increment operator by means of a member function, takes_________., one argument, two argument, no argument, none of the above, C, 1, II, , A, B, C, D, Answer, Marks, Unit, , A, B, C, D, Answer, Marks, Unit, , 56, Pick up the correct statement, i)abstract type of class should contain at least one virtual function, ii)we can create an object of abstract class, iii)abstract class is used to provide an interface to subclasses, iv)abstract class can also have normal function, i and ii only, i , ii, and iii only, i ,iii and iv, all of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 57, What is function overloading, we have to use same function name but different parameter, different function name but same parameter, both a and b, none of the above, A, 1, II, , Id, , 58, , Id, Question
Page 507 :
Question, A, B, C, D, Answer, Marks, Unit, , Virtual base class is used to ____., to perform operator overloading, to perform function overloading, to remove ambiguity in multiple inheritance, all of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 59, Pick up the correct statement, protected member from base class can be accessed by own class and its all subclasses, protected member are not inherited by any other class, Protected member are combination of public and private access member, all of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 60, pick up the correct statement, base class and derived class can have their own constructor, base class and derived class can have their own destructor, neither a or neither b, both a and b, D, 1, II, , Id, Question, , A, B, C, D, Answer, Marks, Unit, , 61, Make a correct sequence of a statement, i)destructor of derived class is called, ii)destructor of base class is called, iii)constructor of derived class is called, iv)constructor of base class is called, i,ii,iv,iii, iv,iii,ii,i, iv,iii,i,ii, i,ii,iii,iv, C, 1, II, , Id, Question, A, , 62, Operator overloading is, making C++ operators work with objects.
Page 508 :
B, C, D, Answer, Marks, Unit, , giving C++ operators more than they can handle., giving new meanings to existing C++ operators., Both A and C, D, 2, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 63, Assume a class C with objects obj1, obj2, and obj3. For the statement obj3 = obj1 - obj2, to work correctly, the overloaded - operator must, take two arguments., return a value., use the object of which it is a member as an operand., Both B and C, D, II, 2, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 64, When you overload an arithmetic assignment operator, the result, goes in the object to the right of the operator., goes in the object to the left of the operator., goes in the object of which the operator is a member., Both B and C, D, 2, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 65, To convert from a user-defined class to a basic type, you would most likely use, a built-in conversion operator., a one-argument constructor., an overloaded = operator., a conversion operator that’s a member of the class., D, 1, II, , Id, Question, , 66, An overloaded operator always requires one less argument than its number, of operands., TRUE, FALSE, , A, B, C, D, Answer, , A
Page 509 :
Marks, Unit, , 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 67, The compiler won’t object if you overload the * operator to perform division., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 68, Inheritance is a way to, make general classes into more specific classes., pass arguments to objects of classes., add features to existing classes without rewriting them., A and C, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 69, Advantages of inheritance include, providing a useful conceptual framework., facilitating class libraries., avoiding the rewriting of code., All of the above, D, 2, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 70, Adding a derived class to a base class requires fundamental changes to the base class., TRUE, FALSE, , Id, Question, , 71, To be accessed from a member function of the derived class, data or functions in the base, class must be, , A, 1, II, , D, 1, II
Page 510 :
A, B, C, D, Answer, Marks, Unit, , public, private, protected, static, C, 1, II, , Id, Question, , 72, If a base class contains a member function basefunc(), and a derived class does not, contain a function with this name, can an object of the derived class access basefunc()?, YES, NO, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, , A, 1, II, 73, If no constructors are specified for a derived class, objects of the derived class will use the, constructors in the base class., TRUE, FALSE, , A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 74, The scope-resolution operator usually, specifies a particular class., tells what base class a class is derived from., resolves ambiguities., A and C, D, 1, II, , Id, Question, , 75, Assume a class Derv that is privately derived from class Base. An object of class Derv, located in main() can access, public members of Derv., protected members of Derv., private members of Derv., , A, B, C
Page 511 :
D, Answer, Marks, Unit, , public members of Base., A, 1, II, , Id, Question, , 76, True or False: A class Dcan be derived from a class C, which is derived from a class B,, which is derived from a class A., TRUE, FALSE, , A, B, C, D, Answer, Marks, Unit, , A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 77, It is illegal to make objects of one class members of another class., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 78, A class hierarchy, shows the same relationships as an organization chart., describes “has a” relationships., describes “is a kind of” relationships., shows the same relationships as a family tree., C, 1, II, , Id, Question, , 79, What is the output of the program?, , B, 1, II, , #include <iostream>, #include <string>, using namespace std;, class Department {, public:, string dept;, Department(string d):dept(d) { }
Page 512 :
A, B, C, D, Answer, Marks, Unit, , void getDeptName() { cout <<dept; }, };, class Student : private Department {, public:, string name;, Student(string n = "Not entered", string d = "ATDC") :, name(n), Department(d) { }, using Department::getDeptName;, };, int main() {, Student s("CSE");, s.getDeptName();, return 0;, }, CSE, ATDC, Not entered, Compilation Error, B, 2, II, , Id, Question, , 80, Identify the lines on which the compiler will report an error., , A, B, C, , #include <iostream>// ---1, using namespace std; // ---2, class Base { // ---3, int var_; // ---4, public: // ---5, Base():var_(0){} // ---6, }; // ---7, class Derived: public Base { public: // ---8, int varD_; // ---9, void print () { cout <<var_; } // ---10, }; // ---11, int main() { // ---12, Derived d; // ---13, d.var_ = 1; // ---14, d.varD_ = 1; // ---15, cout <<d.var_ <<""<<d.varD_; // ---16, return 0; // ---17, } // ---18, 6, 10, 14, 15, 6, 15, 6, 14, 16
Page 513 :
D, Answer, Marks, Unit, , 10, 14, 16, D, 1, II, , Id, Question, , 81, #include <iostream>, using namespace std;, class Base { public:, int var_;, void func(int){}, };, class Derived: public Base { public:, int varD_;, void func(int){}, };, int main() {, Derived d;, d.func(1);, return 0;, }, , A, B, C, D, Answer, Marks, Unit, , Which of the following function will be invoked by d.func(1)?, Base::func(int), Derived::func(int), Compilation Error, None of the above, B, 2, II, , Id, Question, , 82, What is the output of the following program?, #include<iostream>, #include<string>, using namespace std;, class Base {, public:, void func_f1(int i) { cout <<"In base func_f1 "; }, void func_f2(int i) { cout <<"In base func_f2 "; }, };, class Derived: public Base {, public:, void func_f1(int i ) { cout <<"In derived func_f1 "; }, void func_f1(string s) { cout <<"func_f1 string "; }
Page 514 :
A, B, C, D, Answer, Marks, Unit, , void func_f3(int i) { cout <<"In derived func_f3 "; }, };, int main() {, Base b;, Derived d;, d.func_f1(3);, d.func_f1("Blue");, d.func_f3(3);, d.func_f2(3);, return 0;, }, Compilation Error: Cannot add new parameters to func_f1, In derived func_f1 func_f1 string In derived func_f3 In base func_f2, In base func_f2 func_f1 string In derived func_f3 In derived func_f1, Compilation Error: Cannot define func_f3 containing same parameter type as func_f1, B, 2, II, , Id, Question, , 83, What is the output of the following program? {Assume size of int as 4}, , A, B, C, D, Answer, Marks, Unit, , #include<iostream>, using namespace std;, class base {, int data;, };, class derived1: public base { };, class derived2: public derived1 { };, int main() {, cout <<sizeof(derived2);, return 0;, }, 4, 8, 12, 16, A, 1, II, , Id, Question, , 84, What will be the output of the following program?, #include <iostream>
Page 518 :
A, B, C, D, Answer, Marks, Unit, , using namespace std;, class Shape {, public:, int x, y;, Shape(int a = 0, int b = 0): x(a), y(b) {}, void draw(), { cout <<x <<""<<y <<""; }, };, class Rectangle : public Shape {, public:, int w, h;, Rectangle(int a = 5, int b = 6): w(a), h(b), Shape(7, 8) {}, void draw(), { Shape::draw(); cout <<w <<""<<h ; }, };, int main() {, Rectangle *r = new Rectangle(1,2);, r->draw();, return 0;, }, 0012, 7812, 7856, 0056, B, 2, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 89, You cannot change the precedence and associativity of an operator by overloading., TRUE, FALSE, , Id, Question, , 90, When deriving a class from with protected inheritance, public members of the base class, become___________ members of the derived class, and protected members of the, base class become _____________ members of the derived class., protected, protected., public, private, private, private, Private, protected, , A, B, C, D, , A, 1, II
Page 519 :
Answer, Marks, Unit, , A, 2, II, , Id, Question, , 91, When deriving a class with public inheritance, public members of the base class become, __________ members of the derived class, and protected members of the base class, become ___________members of the derived class., private, private, public, protected., protected, protected., private, protected, B, 2, II, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, , 92, C++ provides for ________________, which allows a derived class to inherit from many, base classes, even if the base classes are unrelated., Multilevel inheritance, Single level inheritance, multiple inheritance, Hierarchical inheritance, C, 1, II, 93, __________________is a form of software reuse in which new classes absorb the data, and behaviors of existing classes and embellish these classes with new capabilities., Data hiding, Inheritance, Abstraction, encapsulation, B, 1, II, 94, We can create the object of abstract class, True, False, , B, 1
Page 520 :
Unit, , II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 95, All virtual functions in an abstract base class must be declared as pure virtual functions., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 96, A class is made abstract by declaring that class virtual., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 97, Polymorphic programming can eliminate the need for switch logic., TRUE, FALSE, , Id, Question, , A, B, C, D, Answer, Marks, Unit, , 98, Suppose a and b are integer variables and we form the sum a + b. Now suppose c and, D are floating-point variables and we form the sum c + d. The two +operators here are, clearly being used for different purposes. This is an example of ____________, Operator Overloading, Inheritance, Function Overloading, Constructor, A, 1, II, , Id, Question, , 99, The operators that cannot be overloaded is, , B, 1, II, , B, 1, II, , A, 1, II
Page 521 :
A, B, C, D, Answer, Marks, Unit, , *, ::, (), C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 100, The operators that cannot be overloaded is, *, ?:, >>, <<, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 101, Which of the following operator(s) can not be overloaded, .*, ::, ?:, All of the above, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 102, Which of the following is true about this pointer?, It is passed as a hidden argument to all function calls, It is passed as a hidden argument to all non-static function calls, It is passed as a hidden argument to all static functions, None of the above, B, 1, II, , Id, Question, , 103, Predict the output of following C++ program., #include<iostream>, using namespace std;, class Test, {
Page 522 :
private:, int x;, public:, Test(int x = 0) { this->x = x; }, void change(Test *t) { this = t; }, void print() { cout <<"x = "<<x <<endl; }, };, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, Id, Question, , int main(), {, Test obj(5);, Test *ptr = new Test (10);, obj.change(ptr);, obj.print();, return 0;, }, x=5, x = 10, Compiler Error, Runtime Error, C, 2, II, 104, Which of the followings is/are automatically added to every class, if we do not write our, own., Copy Constructor, Assignment Operator, A constructor without any parameter, All of the above, D, 2, II, 105, What is the output of following program?, #include<iostream>, using namespace std;, class Point {, Point() { cout <<"Constructor called"; }, };, int main(), {, Point t1;
Page 523 :
return 0;, A, B, C, D, Answer, Marks, Unit, , }, Compiler Error, Runtime Error, Constructor called, Segmentation Fault, A, 1, II, , Id, Question, , 106, What will be the output of following program?, #include <iostream>, using namespace std;, class Test, {, public:, Test() { cout <<"Hello from Test() "; }, } a;, , A, B, C, D, Answer, Marks, Unit, Id, Question, , A, B, C, D, Answer, Marks, Unit, , int main(), {, cout <<"Main Started ";, return 0;, }, Main Started, Main Started Hello from Test(), Hello from Test() Main Started, Compiler Error: Global objects are not allowed, C, 2, II, 107, Which of the following operators are overloaded by default by the compiler?, 1) Comparison Operator ( == ), 2) Assignment Operator ( = ), Both 1 and 2, Only 1, Only 2, None of the two, C, 1, II
Page 524 :
A, B, C, D, Answer, Marks, Unit, , 108, A normal C++ operator that acts in a special way on newly defined data types is called, _______, Encapsulated, Overloaded, Classified, Inherited, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 109, The correct function name for overloading the addition + operator is __, Operator _+, Operator :+, Operator (+), Operator +, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 110, Which of the following operators cannot be overloaded?, → operator, . operator, [ ] operator, &operator, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 111, Which of the following operators cannot be overloaded?, +, [], ::, D, 1, II, , Id, Question, A, B, , 112, Pick the incorrect statement from the following, The overloaded operators follow the syntax rules of original operator., Only existing operators can be overloaded, , Id, Question
Page 525 :
C, D, Answer, Marks, Unit, , Overloaded operator must have at least one operand of its class type, Overloaded operators can change the meaning of the original operator, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 113, For operators to be overloaded as non static member functions:, Both binary and unary operators take one argument., Binary operators can have one argument and unary operators can not have any, Neither binary nor unary operators can have arguments, Binary operators can have two arguments and unary operators can have one, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 114, Which of the following is an operator function?, Member overloading, Function overloading, Operator overloading, None of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 115, Operator overloading means _______, Giving new meaning to existing operator without changing its original, Meaning, Making C++ operators to work with objects, Making new types of operator, Both a and b, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 116, For overloading =+ implicitly _______, + and = operators need to be overloaded implicitly, Only + operator need to be overloaded implicitly, Only = operator need to be overloaded implicitly, The += operator cannot be overloaded implicitly, D, 1, II
Page 526 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 117, Overloading a postfix increment operator by means of a member function takes------No argument, One argument, Two arguments, Three Arguments, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 118, If you overload only prefix operator ++ then the postfix ++ operator is ______, Does not work, Works arbitrarily, Works naturally, Works as if prefix ++ operator, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 119, When compiler decides binding of an overloaded member then it is called________, Static binding, Dynamic binding, Local binding, None of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 120, One can redefine the working of _______ to work with objects., Preprocessor directives, White space characters, Standard operators, None of these, C, 1, II, , Id, Question, , 121, Choose the correct option:, I. When you overload <<operator the >>operator automatically gets, overloaded, II. You can overload unary operator to work with binary operator
Page 527 :
A, B, C, D, Answer, Marks, Unit, , Only I is true, Only II is true, Both I and II are true, Neither I nor II are true, D, 1, II, , Id, Question, , A, B, C, D, Answer, Marks, Unit, , 122, Choose the correct option, I.If you do not want to make use of operator overloading, you can achieve that effect, using user defined function, II. The sizeof operator can be overloaded, Only I is true, Only II is true, Both I and II are true, Neither I nor II are true, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 123, The array subscript operator [] when overloaded cannot ______, Take user defined objects are operands, Take float as an operand, Take multiple values inside (for example: [5,7] ), None of these, C, 1, II, , Id, Question, A, B, , 124, The prototype of overloaded cast operator functions do not _______, specify the type they convert to, specify the return type, , C, , need to be defined inside the class whose objects are being converted, , D, , none of these, , Answer, Marks, Unit, , B, 1, II, , Id, , 125
Page 528 :
Question, A, B, C, D, Answer, Marks, Unit, , Which of the following operators cannot be overloaded ?, +=, <<, ?:, FUNCTION CALL(), C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 126, Which of the following operators cannot be overloaded ?, ::, Sizeof, Conditional operator ?:, All of these, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 127, The overloading the function operator________., requires class with overloaded operators, makes use of parameterized constructor, allows to create objects that are syntactically like functions, none of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 128, Choose the incorrect statement from the following., Constructors can be overloaded., Only existing operators must be overloaded, the overloaded operators must follow the syntax rules of the original operator, The overloaded operators must have atleast one operand of its class type, B, 1, II, , Id, Question, A, B, C, D, Answer, , 129, Overloading without explicit arguments to an operator function is called______., unary operator, binary operator, nested class, none of these, A
Page 529 :
Marks, Unit, , 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 130, In binary overloaded function which are overloaded through friend function take_______, three explicit arguments, two explicit arguments, one explicit argument, no argument, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 131, In binary overloaded function which are overloaded through member function, take__________, three explicit arguments, two explicit arguments, one explicit argument, no argument, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 132, The unary operators are overloaded by member function then it takes ______, three explicit arguments, two explicit arguments, one explicit argument, no argument, D, 1, II, , Id, Question, , 133, Choose the correct choice., I. All the operators in C++ can be overloaded., II. We can change the basic meaning of operator while overloading it., Only I is true, Only II is true, Both I and II are true, Neither I nor II are true, D, 1, 2, , A, B, C, D, Answer, Marks, Unit
Page 530 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 134, Which of the following operator can be overloaded through friend function ?, ::, +, =, ->, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 135, The name of the operator function that overloads the / symbol is________., operator /(), /op(), / operator(), op/(), A, 1, II, , Id, Question, , 136, In binary operator overloaded operator function the second operand should be______., , A, B, C, D, Answer, Marks, Unit, , passed by value, Implicit, passed by reference, none of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 137, Function overloading is run time polymorphisms, True, False, , Id, Question, A, B, , 138, Following overloaded operator cannot be inherited by derived class_______., >, =, , B, 1, II
Page 531 :
C, D, Answer, Marks, Unit, , *, /, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 139, Choose the correct choice., The conditional operator can be overloaded, While overloading using the friend function the binary operator requires one argument, Operator precedence cannot be changed, None of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 140, Which of the following operator can be overloaded through friend function ?, (), [], ->, *, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 141, When we overload we want to______., compare and copy object, assign one object to another, compare two objects, test for equality, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 142, Operator overloading is also called one form of polymorphism because_______., the overloaded operators have many forms, the overloaded operators can be declared virtual, the overloaded function can perform various tasks depending upon the type of object, None of these, C, 1, II
Page 532 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 143, Overloading means, two or more methods in the same class that have same name, calling the method which has actual parameters, two or more methods having same name but present in different class, none of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 144, The inheritance mechanism provides meaning of deriving______, new operator from exciting one, new function from exciting one, new class from exciting one, all of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 145, A class derived from the exciting class is known as______, new class, Inheritee, derived class, none of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 146, The derived class is derived from__________, derived class, base class, both a&b, none of these, B, 1, 2, , Id, Question, A, B, C, D, , 147, Which of the following can be derived from base class in inheritace ?, data members, member function, both a&b, none of these
Page 533 :
Answer, Marks, Unit, , C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 148, The inheritance is described as a _____ relationship, has a, is a, association, none of these, B, 1, II, , Id, Question, , 149, Which of the following allows you to create derived class that inherits properties from, more than one base class ?, multilevel inheritance, multiple inheritance, single inheritance, Hybrid inheritance, B, 1, II, , A, B, C, D, Answer, Marks, Unit, , A, B, C, D, Answer, Marks, Unit, , 150, The principle by which the knowledge of general category can be applied to more, specific objects is called _____, polymorphism, overriding, inheritance, none of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 151, Parent:child is________, base:derived, derived:driven, child:super, subclass:superclass, A, 1, II, , Id, Question
Page 534 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 152, What is the syntax of inheritance of a class ?, Class class _name, Class name:access specifier, Class name:access specifier class name, none of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 153, If an attribute is private then which methods have access to it?, Only static methods in the same class, Only the methods defined in that class, Only the methods of the same package, none of these, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 154, Which of the following advantage cannot be achieved by using multiple inheritance?, polymorphism, dynamic binding, both a&b, none of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 155, Which of the symbol used to create multiple inheritance ?, Dot, Comma, Hash #, Dollar, B, 1, II, , Id, Question, A, B, C, D, , 156, Using multiple inheritance, there can be virtual class, it can not be include virtual class, the base classes must have only default constructor, none of these
Page 535 :
Answer, Marks, Unit, , A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 157, The______member function is declared in base class but redefined in derived class, class, overloaded, operator, virtual, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 158, In public inheritance ______, All the members of base class are inherited and are made public, Members of base class that are not private are inherited and retain their access type, All the members of base class are inherited and retain their access type, Only public members of base class are inherited and they remain public, C, 1, II, , Id, Question, , 159, If class C is derived class of class B and class B is a derived class of A. If we instantiate, class B object then the first constructor called belongs to class, A, B, can be A or B, one cannot achieve such inheritance, A, 1, II, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, , 160, When the object of derived class expire, first the _______ is invoked followed by the, ________., derived class constructor, base class destructor, derived class destructor , base class destructor, base class destructor , derived class destructor, none of these, B, 1, II
Page 536 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 161, If class A inherits from class B then B is called ________ ans A is called ________ of B., superclass and subclass, subclass and superclass, subclass and child class, superclass and parent class, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 162, What does derived class does not inherit from the base class _______., constructor and destructor, operator=() members, friends, all of these, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 163, Which constructor will initialise the base class data member ?, Base class, Derived class, Derived derived class, None of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 164, If class A is a friend class of class B, if class B is friend class of class C then_______, class C is friend class of, class A is friend class of, class A and class C do not have any friendship relation., none of these, C, 1, II, , Id, Question, A, B, C, D, , 165, _________ class is tightly coupled with other class., friend, virtual, abstract, none of these
Page 537 :
Answer, Marks, Unit, , A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 166, The keyword friend is used in ___________., the class allowing access to another class, the private section of a class, the public section of a class, all of these, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 167, Class Test:public A, public B is an example of multiple inheritance., False, True, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 168, Which of the following interface determines how your program will be used by other, program?, Public, Private, Protected, None of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 169, When base class pointer points to derived class object___________, it can access only base class members, it can access only derived class members, both base class &derived class members, None of these, A, 1, II, , Id, , 170, , B, 1, II
Page 538 :
Question, A, B, C, D, Answer, Marks, Unit, , The base class will offer_____, more specific object than the derived class, more generalized version of its derived class, empty templates of its derived class, none of these, B, 1, II, , Id, Question, , 171, In my program I have overloaded TEST::operator+ and TEST::operator= What is the, effect on TEST::operator+= ?, The TEST::operator+= will be automatically overloaded .first TEST::operator+ will get, overloaded and then TEST::operator=, The TEST::operator+= will be automatically overloaded .first TEST::operator= will, get overloaded and then TEST::operator+, TEST::operator+= will made invalid, There will be no effect because all three are independent, D, 1, II, , A, B, C, D, Answer, Marks, Unit, , A, B, C, D, Answer, Marks, Unit, , 172, What will happen on execution of the following code ?, Class base, {, };class derived: protected base, {, };, It will not compile as the class body of the base class is not defined, It will not compile as the class body of the derived class is not defined, It will compile successfully, The compilation of above code is dependent upon the type of data provided to it, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 173, The base class will offer_____, more specific object than the derived class, more generalized version of its derived class, empty templates of its derived class, none of these, B, 1, II, , Id, Question
Page 539 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 174, The hybrid inheritance is _____, multiple inheritance, multilevel inheritance, multipath inheritance, both a &c, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 175, Ho, w many types of inheritance are there, 1, 2, 4, 5, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 176, Choose the correct option, a) a constructor can not be called explicitly, b) a destructor is not inherited, c) constructor can not be inherited, d) All of these, D, 1, II, , Id, Question, , A, B, C, D, Answer, Marks, Unit, , 177, Suppose class derived is derived from a class Base. Both the classes contain the, Function name display() that take no argument. What will be the statement in the class, derived which will called the display function of base class, Display(), Base:display(), Base ::display(), Can make such a cell, C, 1, II, , Id, Question, , 178, Suppose class derived is derived from a class Base privately. The object of class Derived
Page 540 :
A, B, C, D, Answer, Marks, Unit, , is located in main() can access_______., public members of base, private member of base, protected members of base, public members of derived, D, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 179, Multiple inheritance causes for a derived class to have ___members., ambiguous, public, private, protected, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 180, What will be the first line of specifier for the class tier, wheel &rubber. Make use of, public rubber, Class Tier:public wheel, public rubber, Class wheel:public tier, public rubber, Class rubber:public tier, public wheel, none of these, A, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 181, Which is the correct class defination for class C ,Which inherits from A &B classes, Class C:A,B, Class C::A,B, Class C:public A,public B, Class C:: public A,Public B, C, 1, II, , Id, Question, , 182, The ability of function or operator to act in different ways on different data type is, called___________, inheritance, polymorphism, encapsulation, , A, B, C
Page 541 :
D, Answer, Marks, Unit, , none of these, B, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 183, _____class that declares or inherits a virtual function., Encapsulation data, Inherited class, Polymorphic class, none of these, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 184, Choose the correct option., A base class may have more then one derived class, Derived class may have more than one derived class, Both a &b, Neither a nor b, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 185, reusability is provided by which feature of c++, polymorphisms, abstraction, derivation, none of the above, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 186, What types of derivations are supported by c++?, single, multiple, multilevel, all of the above, D, 1, II
Page 542 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 1, What is meaning of template parameter?, It is used to pass a type as argument, Used to evaluate a type, It can of no return type, None of the mentioned, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 2, ______Keyword is used in template., Class, Typename, Both a and b, Using, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 3, What is scope of template parameter?, Inside a block only, Inside the class only, Throughout program, All of the above, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 4, Function overloading is also similar to which of the following, Operator overloading, Destructor overloading, Constructor overloading, Virtual function, B, 1, IV, , Id, Question, , 5, Generic programming is approach of______________________which are applicable for, all types, Generalised algorithm, Pseude algorithm, , A, B
Page 543 :
C, D, Answer, Marks, Unit, , Both a and b, None of the above, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 6, Template are of types, Function template, Class template, Both a and b, None of the above, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 7, Class template can be created using________syntax., Template<class T>class classname, Template<class T1,class T2> class classname, Both a and b, None of the above mentioned, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 8, Syntax for creating a function template is, Template<typename t>returntype function name, Template<class T> returntype function name, Both a and b, None of the above mentioned, C, 1, IV, , Id, Question, , 9, Pick up the correct statement, i)template allow us to define generic classes and functions, ii)template support generic programming, iii)function template overloading is possible, i only, i and ii only, ii and iii only, i, ii and iii, D, , A, B, C, D, Answer
Page 544 :
Marks, Unit, , 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 10, Template function can be overloaded, True, False, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 11, Why we use :: template-template parameter?, binding, rebinding, both a &b, none of these, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 12, Which of the things does not require instantiation?, functions, non virtual member function, member class, all of the mentioned, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 13, A template provides a convenient way to make a family of, variables., functions, classes, B and C, D, 1, IV, , Id, Question, A, , 14, Templates automatically create different versions of a function, depending on user input., TRUE, , A, 1, IV
Page 545 :
B, C, D, Answer, Marks, Unit, , FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 15, A template class, is designed to be stored in different containers., works with different data types., generates objects which must all be identical., generates classes with different numbers of member functions., B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 16, There can be more than one template argument., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 17, Actual code for a template function is generated when, the function declaration appears in the source code., the function definition appears in the source code., a call to the function appears in the source code., the function is executed at runtime., C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 18, An exception is typically caused by, the programmer who writes an application‟s code., the creator of a class who writes the class member functions., a runtime error., an operating system malfunction that terminates the program., C, 1, IV, , B, 1, IV, , A, 1, IV
Page 546 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 19, Statements that might cause an exception must be part of a catch block., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 20, Exceptions are thrown, from the catch block to the try block., from a throw statement to the try block., from the point of the error to a catch block., from a throw statement to a catch block., D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 21, A statement that throws an exception does not need to be located in a try block., TRUE, FALSE, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 22, The following is/are errors for which an exception would typically be thrown:, An excessive amount of data threatens to overflow an array., new cannot obtain the requested memory., A power failure shuts down the system., A and B, D, 1, IV, , Id, Question, A, B, C, , 23, Additional information sent when an exception is thrown may be placed in, the throw keyword., the function that caused the error., the catch block., , B, 1, IV, , B, 1, IV
Page 547 :
D, Answer, Marks, Unit, , an object of the exception class., D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 24, A program can continue to operate after an exception has occurred., TRUE, FALSE, , Id, Question, , 25, What is the output of following program?, , A, 1, IV, , #include <iostream>, using namespace std;, int main(), {, int x = -1;, try {, cout <<"Inside try \n";, if (x <0), {, throw x;, cout <<"After throw \n";, }, }, catch (int x ) {, cout <<"Exception Caught \n";, }, , A, , B, , C, , cout <<"After catch \n";, return 0;, }, Inside try, Exception Caught, After throw, After catch, Inside try, Exception Caught, After catch, Inside try
Page 548 :
D, , Answer, Marks, Unit, Id, Question, , A, B, C, D, Answer, Marks, Unit, , Exception Caught, Inside try, After throw, After catch, B, 2, IV, 26, What is the advantage of exception handling?, 1) Remove error-handling code from the software's main line of code., 2) A method writer can chose to handle certain exceptions and delegate others to the, caller., 3) An exception that occurs in a function can be handled anywhere in the function call, stack., Only 1, 1, 2 and 3, 1 and 3, 1 and 2, B, 2, IV, , A, B, C, D, Answer, Marks, Unit, , 27, What should be put in a try block?, 1. Statements that might cause exceptions, 2. Statements that should be skipped in case of an exception, Only 1, Only 2, Both 1 and 2, None of the above, C, 1, IV, , Id, Question, , 28, What is the output of following program, , Id, Question, , #include<iostream>, using namespace std;, class Base {};, class Derived: public Base {};, int main(), {, Derived d;
Page 549 :
try {, throw d;, }, catch(Base b) {, cout<<"Caught Base Exception";, }, catch(Derived d) {, cout<<"Caught Derived Exception";, }, return 0;, , D, Answer, Marks, Unit, , }, Caught Derived Exception, Caught Base Exception, Caught Derived Exception, Caught Base Exception, Compiler Error, B, 1, IV, , Id, Question, , 29, What is the output of following program?, , A, B, C, , #include <iostream>, using namespace std;, int main(), {, try, {, throw 10;, }, catch (...), {, cout <<"default exception\n";, }, catch (int param), {, cout <<"int exception\n";, }, , A, B, C, , return 0;, }, default exception, int exception, default exception
Page 550 :
D, Answer, Marks, Unit, , int exception, Compiler Error, D, 1, IV, , Id, Question, , 30, What is the output of following program?, #include <iostream>, using namespace std;, class Test {, public:, Test() { cout <<"Constructing an object of Test "<<endl; }, ~Test() { cout <<"Destructing an object of Test " <<endl; }, };, , A, B, C, , D, Answer, Marks, Unit, Id, Question, , int main() {, try {, Test t1;, throw 10;, } catch(int i) {, cout <<"Caught "<<i <<endl;, }, }, Caught 10, Constructing an object of Test, Caught 10, Constructing an object of Test, Destructing an object of Test, Caught 10, Compiler Errror, C, 2, IV, 31, What happens in C++ when an exception is thrown and not caught anywhere like, following program?, #include <iostream>, using namespace std;, int fun() throw (int), {
Page 551 :
throw 10;, }, , A, B, C, D, Answer, Marks, Unit, , int main() {, fun();, return 0;, }, Compiler error, Abnormal program termination, Program doesn't print anything and terminates normally, None of the above, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 32, Which alternative can replace the throw statement ?, Exit, For, Break, Return, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 33, Which of the following keyword can not be appered inside the class?, Virtual, Static, Template, Friend, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 34, What is template?, Template is formula for creating a generic class, Template is used to manipulate class, Template is used for creating functions, None of these, A, 1, IV, , Id, , 35
Page 552 :
Question, A, B, C, D, Answer, Marks, Unit, , Select the correct syntax of template:, Template, Template<>, Temp, None of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 36, A class is generated from template class is called _______., inherited class, derived class, generated class, subclass, C, 1, II, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 37, ________ is useful when template of template is used?, Friend function, Static function, Typedef, Inheritance, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 38, Which of the C++ feature allows you to create classes that are dynamic for using data, types?, Templates, Inheritance, Polymorphism, Information hiding, A, 1, IV, , Id, Question, A, B, C, D, , 39, A function template means _______., creating a function having exact type, creating a function without having to specify exact type, both a and b, none of these
Page 553 :
Answer, Marks, Unit, , B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 40, Which of the following is used to describe the function using placeholder type?, Template type parameter, Template parameter, Template type, None of these, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 41, String template is used _____., to replace a string., to replace a string with another string, to delete a string, none of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 42, Maximum number of template argument in function template is _______., two, three, four, many, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 43, Template function must have, one or more than one argument, zero argument, only one argument, at least two arguments, A, 1, IV, , Id, Question, , 44, Template function must have at least ________ generic data type.
Page 554 :
A, B, C, D, Answer, Marks, Unit, , zero, one, two, none of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 45, Templates provide way of abstracting ______ information., type, data, method, access, A, 1, IV, , Id, Question, , 46, If you create instantiation of a class template with an int and then create a second, instantiation with a double then, once the function is used for one data type it becomes unavailable for other type, you can not perform this kind of operation in C++, you must precede each function call with the word int or double, none of these, C, 1, IV, , A, B, C, D, Answer, Marks, Unit, , A, B, C, D, Answer, Marks, Unit, , 47, If templates were removed from C++,Which of the following will be true?, I. Some algorithms could no longer be implemented, II. Any particular algorithms could still be implemented but often less elegantly., Only I is true, Only II is true, Both I and II is true, None of these, D, 1, 4, , Id, Question, A, B, C, , 48, In the template <class T>declaration of T stands for ________., integer data type, arbitary class, generic data types, , Id, Question
Page 555 :
D, Answer, Marks, Unit, , none of these, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 49, What is the meaning of template parameter?, It is used to pass a type as argument, It is used to evalute a type, It has no return type, None of these, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 50, What can be passed by non-type template parameter during compile time?, Int, Double, Char, constant expression, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 51, Choose the correct statement from the following:, Template function will take long time to execute, Template functions are written when you want to have only one code for many different, types, due to template function the duplicate code will get increased, None of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 52, How many types of templates are there in c++?, Two, Three, Four, None Of These, A, 1, IV
Page 556 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 53, What is the task of compiler while handling template?, type association, Portability, code elimination, all of the above, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 54, What should be the name of the parameter that the template should take?, same as class, same as function, same as template, none of these, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 55, Which keyword can be used with template?, Typename, operator, both a and b, None of these, A, 1, IV, , Id, Question, , D, Answer, Marks, Unit, , 56, Which of the following describes a difference between template function and, template class in c++?, The compiler determines the type of a template function's arguments, but, the types of template classes must be stated explicitly when declaring objects, template functions cannot be defined for user-defined types, but template classes can, template classes cannot be defined for user-defined types,but, templatefunctions can., None Of These, A, 1, IV, , Id, Question, A, , 57, What is the validity of templet parameter?, Inside the class, , A, B, C
Page 557 :
B, C, D, Answer, Marks, Unit, , Inside the block, whole program, None of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 58, Which of the following does not required installation ?, Non virtual member function, Member class, Function, All of above, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 59, Which keyword is used to handle the exception ?, Try, Catch, Throw, Exception, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 60, What is the use of the keyword finally ?, It is used at the start of the program for handling all the exceptions, It is used at the end of the program to handle all the exceptions, It can be used anywhere in the program to handle all the exceptions, None of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 61, Which of the following most preferred way of throwing and handling exception?, Throw by value and catch by reference, Throw by reference and catch by value, Throw by value and catch by value, None of these, A, 1, IV
Page 558 :
A, B, C, D, Answer, Marks, Unit, , 62, Which of the following is the most general exception handler that catches exception of, any type?, Catch(std::exception), Catch(std:any_exception), Catch(...), Catch(), C, 1, IV, , Id, Question, A, B, C, D, , 63, Which of the following causes an exception, Missing parenthesis in main(), Calling a function which is not present, A syntax error, a run time error, , Answer, Marks, Unit, , D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 64, Which block should be placed after try block ?, Throw, Catch, both a or b, none of these, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 65, Choose the correct statement, Exception are not suitable for critical points in the program, Exception are suitable for critical points in the program, Both a&b, None of these, A, 1, IV, , Id, Question, A, , 66, In C++ program handling, a try block must be followed by _____catch blocks, exactly one, , Id, Question
Page 559 :
B, C, D, Answer, Marks, Unit, , one or more, exactly two, none of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 67, The process of handling the actual exception occurs _________, inside the program, outside the program, both a &b, none of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 68, Which of the following is used to check the error in the block?, Try, Throw, Catch, None of these, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 69, What should be present when throwing object ?, Constructor, Destructor, copy constructor, none of these, C, 1, IV, , Id, Question, A, , 70, For handling the exception in C++ _______ are used, catch handlers, , B, C, D, Answer, Marks, , exception handlers, Pointers, none of these, B, 1
Page 560 :
Unit, , IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 71, For handling the exceptions in C++ _________ is used ., handler function, terminate function, both a &b, none of these, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 72, How many parameters does the throw expression can have ?, 0, 1, 2, 3, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 73, What kind of exceptions are used in C++, Handled, Unhandled, Static, Dynamic, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 74, What will happen when exception is uncaught?, Arise an error, program will run, execute in a loop, none of these, A, 1, IV, , Id, Question, A, , 75, Choose the correct statement, A function can throw any type of exception
Page 561 :
B, C, D, Answer, Marks, Unit, , a function can throw an exception of certain type only, A exception can't throw any type of exception, none of these, B, 1, 4, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 76, What fuunction will be called when we have uncaught exception?, Catch, Throw, Terminate, none of these, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 77, What will happen when a programs throws any other of exception other than specified ?, still execute, Terminate, raise an error, none of these., C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 78, Which statement is used to catch all types of exceptions?, catch(), catch(Test t), catch, none of these, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 79, Which keyword can be used as a template, Exception, Typename, both a & b, Function, B, 1, IV
Page 562 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 80, An Exception is thrown using _____________keyword in cpp, Throws, Throw, Threw, Thrown, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 81, Which parameter is legal for non-type template?, pointer to member, object, class, none of these, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 82, Which of the things does not require instantiation?, functions, Non virtual member function, member class, all of these, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 83, Which of the following permits function overloading on c++?, Data Type, Number of arguments, A &B both, none of these, C, 1, IV, , Id, Question, A, B, C, , 84, Function overloading is also similar to which of the following?, Operator Overloading, Constructer overloading, Destructor overloading
Page 563 :
D, Answer, Marks, Unit, , none of the above, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 85, Which is dependent on template parameter, base class, abstract class, method, none of the above, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 87, How to declare a template?, Tem, Temp, Template<>, none of these, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 88, What may be the name of parameter that the template should take?, same as template, same as class, same as function, none of these, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 89, Which is used to handle the exceptions in c++?, catch handler, handler, exception handler, all of these, B, 1, IV, , Id, , 90
Page 564 :
Question, A, B, C, D, Answer, Marks, Unit, , Which is called on allocating the memory for array of objects?, Function, Method, Destructor, Constructor, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 91, Which value is placed in the base class?, Inherited value, Derived value, Default type values, Both a and b, C, IV, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 92, Which is used to get the input during runtime?, cout, cin, Template, All of the above, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 93, __________is used to perform the generic programming., Class, Template, Function, Inheritance, All of the above, B, IV, , Id, Question, A, B, C, D, Answer, , 94, A template can be considered as a kind of macros, True, False, , A
Page 565 :
Marks, Unit, , 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 95, We can not define more than 2 placeholder in class/function template., False, True, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 96, When template is defined with parameter that would be replaced by specified _______at, the time of actual use of class or function., Keyword, Operator, Datatype, None of the above mentioned, C, IV, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 97, Templates sometimes called as ___________, Parameterized classes, Parameterized function, Both a and b, None of the above mentioned, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 98, Exceptions are of type, Synchronous, Asynchronous, Both a and b, None of the above mentioned, C, 1, IV, , Id, Question, , 99, “out-of-range”, “overflow” are the type of exceptions, , A, 1, IV
Page 566 :
A, B, C, D, Answer, Marks, Unit, , Asynchronous, Synchronous, Default, None of the above, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 100, The most type of error--------., Logical error, Syntactic error, Both a and b, Class, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 101, Run time error is known as ______, Logical error, Syntactic error, Exception, All of the above mentioned, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 102, How the exception is throw, throw exception, throw(exception), throw, All of the above, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, , 103, Can we throw exception more than one time, True, False, , A, 1
Page 567 :
Unit, , IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 104, Which statement we have to use rethrowing exception, throw(exception), Throw, Both a and b, None of the above mentioned, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 105, Exception can be handle if_______, Throwing argument is match with catch block, Throwing argument is not match with catch block, Exception is not thrown, None of the abve, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 106, With this concept same algorithm can be used for different data types, Procedure oriented paradigm, Generic programming, Both a and b, None of the above, B, 1, IV, , Id, Question, , 106, Template is a way creating generalize functions and classes which are applicable for all, data types, False, True, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, , B, 1, IV, 107, Class template is applicable for ___., For function only
Page 568 :
B, C, D, Answer, Marks, Unit, , For that class only, Both a and b, None of the above mentioned, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 108, Function template is applicable for_________., For function only, For that class only, Both a and b, None of the above mentioned, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 109, How many kinds of parameters are there in c++, 1, 2, 3, 4, C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 110, Which type of program is recommended to include in try block, Static memory allocation, Dynamic memory allocation, Const reference, Pointer, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 111, How to handle error in destructor, Throwing, Terminate, Both a and b, None of the mentioned, B, 1, IV
Page 569 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 112, In catch statement we have multiple parameters, Yes, No, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 113, ------kind of exceptions are in c++., Handled, Static, Both a and b, Unhandled, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 114, Pick up the correct statement, To throw exception we have to use catch statement, Error occurring code is placed in try block, We can not have multiple throwing mechanism in c++, Both and b, B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 115, Can we used constructor for exception handling, Yes, No, , Id, Question, A, B, C, , 116, Class template can be overloaded, True, False, , B, 1, IV, , A, 1, IV
Page 570 :
D, Answer, Marks, Unit, , B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 117, ______is a generic class handler, Catch(---), Catch(-,-), Catch(…), Catch(void), C, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 118, If the exception is not handled then which standard library function get invoked, stop(), terminate(), Read(), Write(), B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 119, Exception can be only built in type, True, False, , Id, Question, , 120, What will be output of program, #include<iostream>, using namespace std;, template<class T>, T display(T x), {, cout<< “using template x=”<<x<<“\n”;, }, int display(int x), {, , A, 1, IV
Page 571 :
A, , B, , C, , D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, , cout<<“Normal display x=”<<x <<“\n”;, }, int main(), {, display(2.3);, display(3);, diplay(1.1);, }, Normal display x=2.3, Using template x=3, Normal display x=1.1, using template x=2.3, Normal display x=3, using template x=1.1, using template x=3, Normal display x=2.3, using template x=1.1, None of the above, B, 2, IV, 121, In nested try blocks, there is no need to specify catch handler for inner try block. Outer, catch handler is sufficient for the program, True, False, , B, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 122, Can we write try block within try block, True, False, , Id, Question, A, , 123, Can we prevent a function from throwing any exceptions, Yes, , A, 1, IV
Page 572 :
B, C, D, Answer, Marks, Unit, , No, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 124, What is return type of uncaught_exception() is---Char*, Double, Int, Bool, D, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 125, Can we write a throw statement inside catch statement, Yes, No, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 126, We can define our own exceptions in c++, False, True, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 127, Stack unwinding deals with, Polymorphism, inheritance, Exception handling, Classes, C, 1, IV, , A, 1, IV, , A, 1, IV, , B, 1, IV
Page 573 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 128, What is STL, Standard Term Library, Standard Tree Library, Standard Template Library, None of the above mentioned, C, 1, IV, , Id, Question, , A, B, C, D, Answer, Marks, Unit, , 129, Pick up the correct statement, •, Catch statement be placed immediately after try block, •, It can have multiple parameters, •, There must be multiple catch handler for a try block, •, Generic catch statement we can placed anywhere in program, i and ii, i and iii, i and iv, i , ii and iii, B, 2, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 130, Generic catch should be placed at, End of all statement, Before try, Before throw, Inside try, A, 1, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 131, Irrespective of exception occurrence, catch handler will be always executed, Yes, No, , Id, , 132, , B, 1, IV
Page 574 :
Question, A, B, C, D, Answer, Marks, Unit, , From where does the template class can derived, Regular non-templated c++ class, Templated class, Both a and b, None of the above mentioned, C, 2, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 133, What is done by compiler for templates, Type-safe, Code elimination, Portability, All of the above mentioned, A, 2, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 134, Catch handler itself may detect and throw an exception, True, False, , Id, Question, , 135, If the thrown exception will not be caught by any catch statement then it will be passed to, next outer try/catch sequence for processing., False, True, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, , A, 1, Iv, , B, 1, IV, 136, While specifying the exceptions, the type-list specifies the________ that may be thrown., How many exceptions, Type of exception, Both a and b, None of the above mentioned
Page 575 :
Answer, Marks, Unit, , B, 2, IV, , Id, Question, , 137, When an exception is rethrown ,it will not be caught by the__________or other catch in, that group., Same catch, Nested catch, Both a and b, None of the above mentioned, A, 2, IV, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, , 138, Try block can throw any exception, True, False, , Id, Question, , 139, Pick up the correct statement from the following, •, Multiple catch statement are there in c++., •, We have generic catch statement to handle all type of exception, •, Try block is used to throw and exception, , A, B, C, D, Answer, Marks, Unit, , i and iii, i, ii, i and ii only, D, 2, IV, , Id, Question, A, B, C, D, Answer, , 140, When an exception is not caught, Program is go in wait condition, Program is aborted, Program works fine way, None of the above mentioned, B, , B, 1, IV
Page 576 :
Marks, Unit, , 1, IV, , Id, Question, , 141, We can place two or more catch blocks together to catch and handle multiple types of, exceptions thrown by a try blocks, True, False, , A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, Id, Question, A, B, C, D, Answer, Marks, Unit, , A, 1, IV, 142, It is also possible to make a catch statement to catch all types of exceptions using ellipses, as its arguments, True, False, , A, 1, IV, 143, We can restrict a function to throw only a set of specified exceptions by adding a throw, specification clause to the function definition., True, False, , A, 1, IV, 144, We may also use non-type parameters such basic or derived data types as arguments, template, True, False, , A, 1, IV
Page 577 :
Id, Question, , A, B, C, D, Answer, Marks, Unit, Id, Question, , A, , B, , C, , D, , 145, Pick up the correct statement from the following related with overloading of template, functions, • Call an ordinary function that has an exact match, • Call a template function that could be created with an exact macth, • Try normal overloading resolution to ordinary functions and call the one, that matches, 1 and 2 only, 2 and 3 only, All of the above, None of the above mentioned, C, 2, IV, 146, What will be output of the a following program, #include<iostream>, using namespace std;, template <class T>, void display(T x), {, cout<<“Template display:”<<x<< “\n”;, }, void display(int x), {, cout<<“Explicit display:”<<x <<“\n”;, }, int main(), {, display(100);, display(12.34);, display(„c‟);, }, Template display:100, Template display:12.34, Template display: c, Explicit display:100, Template display:12.34, Template display: c, Explicit display:100, Template display:12.34, Explicit display: c, Template display:100, Template display:12.34
Page 578 :
Answer, Marks, Unit, Id, Question, , A, , B, C, , D, Answer, Marks, Unit, Id, Question, , Template display: c, B, 2, IV, 147, What will be output of program, #include <iostream>, using namespace std;, int main(), {, cout <<"Start\n";, try {, cout <<"Inside try block\n";, throw 100;, cout << "This will not execute";, }, catch (int i) {, cout <<"Caught an exception -- value is: ";, cout <<i <<"\n";, }, cout <<"End";, return 0;, }, Start, Inside try block, Caught an exception -- value is: 100, End, Start, End, Start, Inside try block, End, None of the above mentioned, A, 2, IV, 148, What will be output of following program, #include <iostream>, using namespace std;, void Xhandler(int test), {, try{, if(test) throw test;
Page 579 :
A, , B, , C, , D, Answer, Marks, Unit, Id, Question, , else throw "Value is zero";, }, catch(int i) {, cout << "Caught Exception #: " <<i <<'\n';, }, catch(const char *str) {, cout <<"Caught a string: ";, cout << str <<'\n';, }, }, int main(), {, cout <<"Start\n";, Xhandler(1);, Xhandler(2);, Xhandler(0);, Xhandler(3);, cout << "End";, return 0;, }, Start, Caught Exception #: 1, Caught Exception #: 2, Caught Exception #: 0, Caught Exception #: 3, End, Start, Caught Exception #: 1, Caught Exception #: 2, Caught a string: 0, Caught Exception #: 3, End, Start, Caught Exception #: 1, Caught Exception #: 2, Caught a string: Value is zero, Caught Exception #: 3, End, None of the mentioned, C, 2, IV, 149, What will be output of program, #include <iostream>
Page 580 :
A, , B, C, , using namespace std;, void Xhandler(int test), {, try{, if(test==0) throw test; // throw int, if(test==1) throw 'a'; // throw char, if(test==2) throw 123.23; // throw double, }, catch(int i) { // catch an int exception, cout <<"Caught an integer\n";, }, catch(...) { // catch all other exceptions, cout <<"Caught One!\n";, }, }, int main(), {, cout <<"Start\n";, Xhandler(0);, Xhandler(1);, Xhandler(2);, cout <<"End";, return 0;, }, Start, Caught One!, Caught One!, Caught One!, End, , Answer, Marks, Unit, , Start, Caught an integer, Caught One!, Caught One!, End, Start, Caught One!, Caught an integer, Caught One!, End, C, 2, None of the above mentioned, , Id, Question, , 150, What will be output of following program, , D
Page 581 :
A, B, C, D, Answer, Marks, Unit, , #include <iostream>, using namespace std;, template <class Type1, class Type2> class myclass, {, Type1 i;, Type2 j;, public:, myclass(Type1 a, Type2 b) { i = a; j = b; }, void show() { cout <<i << ' ' <<j <<'\n'; }, };, int main(), {, myclass<int, double>ob1(10, 0.23);, myclass<char, char *>ob2('X', "Templates add power.");, ob1.show(); // show int, double, ob2.show(); // show char, char *, return 0;, }, 10 0.23, X Templates add power., 0.23 10, X Template add power, 10 10, X template add power, Compilation error, A, 2, IV, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 151, We can combine operator overloading with a class, True, False, , Id, Question, , 152, If you overload a generic function, that overloaded function overrides (or "hides") the, generic function relative to that specific version., True, False, , A, B, C, D, , A, 1, IV
Page 582 :
Answer, Marks, Unit, , A, 1, IV, , Id, Question, , 153, What will be output of following programming, #include <iostream>, using namespace std;, template <class T>, T GetMax (T a, T b) {, T result;, result = (a>b)? a : b;, return (result);, }, int main () {, int i=5, j=6, k;, long l=10, m=5, n;, k=GetMax<int>(i,j);, n=GetMax<long>(l,m);, cout <<k << endl;, cout <<n <<endl;, return 0;, }, 6, 10, 5, 5, 10, 10, Compilation error, A, 2, IV, , A, B, C, D, Answer, Marks, Unit, Id, Question, , 154, What will be output of following program, #include <iostream>, using namespace std;, template <class T>, class mypair {, T a, b;, public:, mypair (T first, T second), {a=first; b=second;}, T getmax ();, };
Page 583 :
A, B, C, D, Answer, Marks, Unit, Id, Question, , A, B, , template <class T>, T mypair<T>::getmax (), {, T retval;, retval = a>b? a : b;, return retval;, }, int main () {, mypair <int>myobject (100, 75);, cout << myobject.getmax();, return 0;, }, 75, 100, 75, 100, Compilation error, B, 2, IV, 155, What will be output of following program, #include <iostream>, #include <exception>, using namespace std;, class myexception: public exception, {, virtual const char* what() const throw(), {, return "My exception happened";, }, } myex;, int main () {, try, {, throw myex;, }, catch (exception&e), {, cout << e.what() <<endl;, }, return 0;, }, Exception happened, My exception happened.
Page 584 :
C, D, Answer, Marks, Unit, , Run Time error, Compilation error, B, 2, IV, , Id, Question, , 156, Pick up the correct statement from following, 1.Exception handling is not supported c++, 2.Template support generic programming in c++, 3.overloading of function template is possible in c++, 4.generic catch template can handle all types of exceptions, 2 and 3 only, 3 and 4 only, 1, 2 and 3 only, 2, 3 and 4 only, D, 2, IV, , A, B, C, D, Answer, Marks, Unit
Page 585 :
A, B, C, D, Answer, Marks, Unit, , 1, What does the following statement mean?, int (*fp)(char*), pointer to a pointer, pointer to an array of chars, pointer to function taking a char* argument and returns an int, function taking a char* argument and returning a pointer to int, C, 1, III, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 2, The operator used for dereferencing or indirection is ____, *, &, ->, –>>, A, 1, III, , Id, Question
Page 586 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 3, Choose the right option, string* x, y;, x is a pointer to a string, y is a string, y is a pointer to a string, x is a string, both x and y are pointer to string types, none of the mentioned, A, 1, III
Page 587 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 4, Which one of the following is not a possible state for a pointer?, hold the address of the specific object, point one past the end of an object, Zero, point to a byte, D, 1, III
Page 588 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 5, Which of the following is illegal?, int *ip;, string s, *sp = 0;, int i; double* dp = &i;, int *pi = 0;, D, 1, III
Page 589 :
Id, Question, , 6, , A, B, C, D, Answer, Marks, Unit, , 10, 15, 20, Random number, D, 2, III, , #include <iostream>, using namespace std;, int main(), {, int a = 5, b = 10, c = 15;, int *arr[ ] = {&a, &b, &c};, cout <<arr[1];, return 0;, }
Page 590 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 7, The correct statement for a function that takes pointer to a float, a pointer to a pointer to a, char and returns a pointer to a pointer to a integer is, int **fun(float**, char**), int *fun(float*, char*), int ***fun(float*, char**), int ***fun(*float, **char), C, 1, III
Page 592 :
ptr += 5;, cout << ptr;, return 0;, }, A, B, C, D, Answer, Marks, Unit, , fg, cdef, defg, abcd, A, 2, III, , Id, Question, A, B, C, D, , 10, Which rule will not affect the friend function?, private and protected members of a class cannot be accessed from outside, private and protected member can be accessed anywhere, both a &b, None
Page 593 :
Answer, Marks, Unit, , A, 1, III, , Id, Question, A, B, C, D, , 11, Which keyword is used to declare the friend function?, Firend, friend, Classfriend, myfriend
Page 595 :
{, width = wid;, }, void printWidth( Box box ), {, box.width = box.width * 2;, cout << "Width of box : " << box.width << endl;, }, int main( ), {, Box box;, box.setWidth(10.0);, printWidth( box );, return 0;, }, A, B, C, D, Answer, Marks, Unit, , 40, 5, 10, 20, D, 2, III, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 13, Pick out the correct statement., A friend function may be a member of another class., A friend function may not be a member of another class., A friend function may or may not be a member of another class., None of the mentioned, C, 1, III
Page 596 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 14, Where does keyword „friend‟ should be placed?, function declaration, function definition, main function, None, A, 1
Page 597 :
Id, Question, , 15, #include <iostream>, using namespace std;, class sample, {, private:, int a, b;, public:, void test(), {, a = 100;, b = 200;, }
Page 598 :
friend int compute(sample e1);, };, int compute(sample e1), {, return int(e1.a + e1.b) - 5;, }, int main(), {, sample e;, e.test();, cout << compute(e);, return 0;, }, A, B, C, D, Answer, Marks, Unit, Id, Question, , 100, 200, 300, 295, D, 2, 16, #include <iostream>, using namespace std;, class base, {, int val1, val2;, public:, int get(), {, val1 = 100;, val2 = 300;, }, friend float mean(base ob);, };, float mean(base ob), {, return float(ob.val1 + ob.val2) / 2;, }, int main(), {, base obj;, obj.get();, cout << mean(obj);, return 0;, }
Page 599 :
A, B, C, D, Answer, Marks, Unit, , 200, 150, 100, 300, , Id, Question, A, B, C, D, Answer, Marks, Unit, , 17, To which does the function pointer point to?, Variable, Constants, Function, absolute variables, C, 1, , 2
Page 600 :
Id, Question, A, B, C, D, Answer, Marks, Unit, , 18, What we will not do with function pointers?, allocation of memory, de-allocation of memory, both a &b, None, C, 1