InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 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) ConstantsI had been asked this question during a job interview.My query is from Data Members topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Right answer is (a) Data members |
|
| 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 initializedI had been asked this question in an internship interview.The origin of the question is Data Members topic in section Class Members & Types of Object Oriented Programming |
|
Answer» The CORRECT choice is (b) Can be initialized only with help of constructors |
|
| 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 constructorThis question was posed to me in an interview for job.My doubt stems from Data Members topic in division Class Members & Types of Object Oriented Programming |
|
Answer» The CORRECT choice is (d) Static data MEMBERS are DEFINED outside class, not in constructor |
|
| 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 usedThe question was posed to me in semester exam.My question is from Data Members topic in division Class Members & Types of Object Oriented Programming |
|
Answer» Correct option is (a) The STRUCTURE must have been defined before class. |
|
| 5. |
How many data members can a class contain?(a) 27(b) 255(c) 1024(d) As many as requiredI have been asked this question during an interview.Query is from Data Members in portion Class Members & Types of Object Oriented Programming |
|
Answer» Right answer is (d) As many as REQUIRED |
|
| 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 callI had been asked this question during an interview.My question is from Data Members topic in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Right CHOICE is (c) Dot or arrow as required |
|
| 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 memberI had been asked this question in an international level competition.This intriguing question originated from Data Members in section Class Members & Types of Object Oriented Programming |
|
Answer» The CORRECT choice is (a) Return the address of the private DATA member using a member function |
|
| 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 useI have been asked this question in an international level competition.The above asked question is from Data Members topic in chapter Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT option is (d) Considered a red flag, and not recommended for large scale use The best 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. |
The static member functions can only use ________(a) Static data members(b) Private data members(c) Protected data members(d) Constant data membersI had been asked this question in a job interview.The query is from Data Members in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct answer is (a) STATIC data MEMBERS |
|
| 10. |
A class can have self-referential data members.(a) True(b) FalseI have been asked this question in semester exam.The doubt is from Data Members topic in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Right choice is (b) False |
|
| 11. |
What is the keyword used to make data members have same value?(a) static(b) const(c) double(d) abstractThe question was asked in an international level competition.Enquiry is from Data Members topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Right OPTION is (b) const |
|
| 12. |
Which data members can be inherited but are private to a class?(a) Private(b) Protected(c) Protected and Static(d) Privately inheritedI have been asked this question in an interview.The origin of the question is Data Members in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Correct answer is (b) Protected |
|
| 13. |
The arguments passed to member functions by reference are considered as data members of class.(a) True(b) FalseThe question was posed to me during an interview.This intriguing question comes from Data Members topic in section Class Members & Types of Object Oriented Programming |
|
Answer» The correct option is (b) False |
|
| 14. |
Which among the following is not allowed for data member declaration?(a) int a;(b) static int a;(c) abstract a;(d) Boolean a;The question was asked during an internship interview.This intriguing question comes from Data Members in section Class Members & Types of Object Oriented Programming |
|
Answer» The CORRECT answer is (c) abstract a; |
|
| 15. |
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 classThis question was addressed to me in semester exam.My query is from Member Functions topic in division Class Members & Types of Object Oriented Programming |
|
Answer» RIGHT CHOICE is (b) Functions belonging a class 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. |
|
| 16. |
How many types of member functions are generally there in C++?(a) 2(b) 3(c) 4(d) 5I had been asked this question in a national level competition.My question is taken from Member Functions topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Correct CHOICE is (d) 5 |
|
| 17. |
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 nameI had been asked this question by my college professor while I was bunking the class.I would like to ask this question from Member Functions topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Correct choice is (d) USING DOT, arrow or using scope RESOLUTION operator with class name |
|
| 18. |
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 lineI got this question during an internship interview.My query is from Member Functions topic in chapter Class Members & Types of Object Oriented Programming |
|
Answer» The CORRECT option is (b) Member FUNCTIONS WHOSE definition is expanded in place of its call |
|
| 19. |
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 usedThe question was asked in homework.Origin of the question is Member Functions topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Right option is (a) Compile TIME ERROR |
|
| 20. |
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 referredI had been asked this question during an interview for a job.My query is from Member Functions topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Right CHOICE is (c) Doesn’t CONTAIN “this” pointer |
|
| 21. |
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 pointerThis question was addressed to me in an online quiz.This is a very interesting question from Member Functions in section Class Members & Types of Object Oriented Programming |
|
Answer» The correct ANSWER is (d) USED directly or with this POINTER |
|
| 22. |
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 functionThis question was addressed to me during an interview.My question is based upon Member Functions in section Class Members & Types of Object Oriented Programming |
|
Answer» The correct answer is (C) MUST be non-static member and should not be FRIEND of class |
|
| 23. |
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 derivedThe question was posed to me in homework.This interesting question is from Member Functions topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct answer is (a) It should not contain any body and DEFINED by subclasses |
|
| 24. |
Member functions of a generic class are _____________(a) Not generic(b) Automatically generic(c) To be made generic explicitly(d) Given default type as doubleI have been asked this question in an online quiz.My question is from Member Functions in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Correct answer is (b) Automatically GENERIC |
|
| 25. |
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 membersThis question was addressed to me in semester exam.This interesting question is from Member Functions in division Class Members & Types of Object Oriented Programming |
|
Answer» Right OPTION is (a) Access all the members of the class |
|
| 26. |
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 functionsI had been asked this question in class test.This interesting question is from Member Functions in section Class Members & Types of Object Oriented Programming |
|
Answer» Correct option is (a) Call other member functions |
|
| 27. |
Which member function doesn’t require any return type?(a) Static(b) Constructor(c) Const(d) Constructor and destructorI have been asked this question during an interview.My question comes from Member Functions in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Right choice is (d) CONSTRUCTOR and destructor |
|
| 28. |
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 classThe question was posed to me in an international level competition.This key question is from Member Functions in section Class Members & Types of Object Oriented Programming |
|
Answer» Right choice is (c) ACCESS PUBLIC members of SUBCLASS |
|
| 29. |
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 structureThis question was posed to me in an internship interview.I would like to ask this question from Local Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct option is (b) CLASSES DECLARED inside a function |
|
| 30. |
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 programI had been asked this question in an interview.My query is from Local Class in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct choice is (c) Defined INSIDE the CLASS body |
|
| 31. |
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 anywayThe question was asked in semester exam.The above asked question is from Local Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT option is (d) No, it can’t ACCESS In anyway Best 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. |
|
| 32. |
Which type of data can a local class access from the function in which it is defined?(a) Static and extern(b) Abstract and static(c) Void and extern(d) Const and staticI had been asked this question by my college professor while I was bunking the class.I need to ask this question from Local Class in division Class Members & Types of Object Oriented Programming |
|
Answer» Correct ANSWER is (a) Static and extern |
|
| 33. |
Local classes can access the type names and enumerators defined by the enclosing function.(a) True(b) FalseThe question was asked in an interview for job.My question is from Local Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct ANSWER is (a) True |
|
| 34. |
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 anywayThis question was posed to me in an online interview.I would like to ask this question from Local Class topic in chapter Class Members & Types of Object Oriented Programming |
|
Answer» The correct answer is (d) No, not possible anyway |
|
| 35. |
All the member functions of local classes are __________ by default.(a) Static(b) Inline(c) Abstract(d) VirtualThe question was posed to me in a national level competition.This question is from Local Class in division Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT option is (c) Abstract The BEST I can EXPLAIN: 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. |
|
| 36. |
The enclosing function has no special access to the members of the local class.(a) True(b) FalseI got this question during an online exam.Origin of the question is Local Class topic in division Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT option is (a) True The best I can explain: 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. |
|
| 37. |
Which language can use inheritance with local classes?(a) Kotlin(b) Java(c) SmallTalk(d) SAP ABAPThis question was addressed to me in an interview for job.This intriguing question originated from Local Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT option is (d) SAP ABAP The 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. |
|
| 38. |
How many local classes can be defined inside a single function?(a) Only 1(b) Only 3(c) Only 5(d) As many as requiredThe question was asked in examination.Origin of the question is Local Class in section Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT answer is (d) As many as required The 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. |
|
| 39. |
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 functionI have been asked this question in class test.My question is from Local Class in chapter Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT answer is (b) Defined in constructor For 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. |
|
| 40. |
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(d) No, ambiguity arisesThe question was asked during a job interview.Question is from Local Class in division Class Members & Types of Object Oriented Programming |
|
Answer» The correct ANSWER is (a) YES, since local |
|
| 41. |
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 programThe question was posed to me in an international level competition.I need to ask this question from Local Class in division Class Members & Types of Object Oriented Programming |
|
Answer» Correct CHOICE is (b) WITHIN the function |
|
| 42. |
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 accessI had been asked this question during an interview.Asked question is from Local Class topic in division Class Members & Types of Object Oriented Programming |
|
Answer» CORRECT ANSWER is (d) No, can’t ACCESS 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. |
|
| 43. |
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 functionThis question was addressed to me by my school teacher while I was bunking the class.Enquiry is from Local Class topic in section Class Members & Types of Object Oriented Programming |
|
Answer» The correct OPTION is (c) Helps to add extra functionality to a function |
|
| 44. |
Which among the following best describes a nested class?(a) Class inside a class(b) Class inside a function(c) Class inside a package(d) Class inside a structureThe question was asked during an interview.My question comes from Nested Class in portion Class Members & Types of Object Oriented Programming |
|
Answer» Correct option is (a) CLASS inside a class |
|
| 45. |
Which feature of OOP reduces the use of nested classes?(a) Encapsulation(b) Inheritance(c) Binding(d) AbstractionThe question was posed to me during an online exam.My question is based upon Nested Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» Correct CHOICE is (B) INHERITANCE |
|
| 46. |
How many categories are nested classes divided into?(a) 2(b) 3(c) 4(d) 5This question was posed to me in unit test.My doubt stems from Nested Class in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Correct CHOICE is (a) 2 |
|
| 47. |
Non-static nested classes have access to _____________ from enclosing class.(a) Private members(b) Protected members(c) Public members(d) All the membersThis question was addressed to me in final exam.Question is from Nested Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct option is (d) All the MEMBERS |
|
| 48. |
Static nested classes doesn’t have access to _________________ from enclosing class.(a) Private members(b) Protected members(c) Public members(d) Any other membersThis question was posed to me in an interview for internship.I'd like to ask this question from Nested Class topic in portion Class Members & Types of Object Oriented Programming |
|
Answer» The correct choice is (d) Any other members |
|
| 49. |
The nested class can be declared ___________________(a) Public(b) Private(c) Protected(d) Public, Protected, Private or Package privateThe question was posed to me by my college director while I was bunking the class.My doubt is from Nested Class topic in chapter Class Members & Types of Object Oriented Programming |
|
Answer» Correct answer is (d) PUBLIC, PROTECTED, PRIVATE or PACKAGE private |
|
| 50. |
Use of nested class ____________ encapsulation.(a) Increases(b) Decreases(c) Doesn’t affect(d) Slightly decreasesI have been asked this question in an interview for job.Enquiry is from Nested Class in chapter Class Members & Types of Object Oriented Programming |
|
Answer» RIGHT option is (a) Increases To EXPLAIN I would say: 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. |
|