Object Oriented Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Object Oriented Programming MCQ (Multiple Choice Questions)

 Que- 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 


Ans- Considered a red flag, and not recommended for large scale use  


Que- The static member functions can only use ________ 

a. Static data members 

b. Private data members 

c. Protected data members 

d. Constant data members 


Ans- Static data members  


Que- What is the keyword used to make data members have same value? 

a. static 

b. const 

c. double 

d. abstract 


Ans- const  


Que- Which data members can be inherited but are private to a class? 

a. Private 

b. Protected 

c. Protected and Static 

d. Privately inherited 


Ans- Protected  


Que- Which among the following is not allowed for data member declaration? 

a. int a; 

b. static int a; 

c. abstract a; 

d. Boolean a; 


Ans- abstract a;  


Que- 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 


Ans- Functions belonging a class  


Que- How many types of member functions are generally there in C++? 

a. 2 

b. 3 

c. 4 

d. 5 


Ans- 5  


Que- How can a static member function be called in 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 


Ans- Using dot, arrow or using scope resolution operator with class name  


Que- 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 


Ans- Member functions whose definition is expanded in place of its call  


Que- 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 


Ans- Compile time error  


Que- 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 


Ans- Doesn't contain "this" pointer  


Que- 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 


Ans- Used directly or with this pointer  


Que- 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 


Ans- Must be non-static member and should not be friend of class  


Que- 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 


Ans- It should not contain any body and defined by subclasses  


Que- 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 


Ans- Automatically generic  


Que- 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 


Ans- Access all the members of the class  


Que- Which among the following is proper syntax for class given below?advertisementclass A{  

a. int a,b; 

b. public : void disp();} 

c. void disp::A(){ } 

d. void A::disp(){ } 


Ans- void A:disp() { cout<<a<<b ; }  


Que- 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 


Ans- Call other member functions  


Que- Which member function doesn't require any return type? 

a. Static 

b. Constructor 

c. Const 

d. Constructor and destructor 


Ans- Constructor and destructor  


Que- 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 


Ans- Access public members of subclass  


Que- 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 


Ans- Classes declared inside a function  


Que- 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 


Ans- Defined inside the class body  


Que- Can local class members access/use the general local variables (except static, abstract et

c.) 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 


Ans- No, it can't access In anyway  


Que- 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 static 


Ans- Static and extern  


Que- 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 


Ans- No, not possible anyway  


Que- All the member functions of local classes are __________ by default. 

a. Static 

b. Inline 

c. Abstract 

d. Virtual 


Ans- Abstract  


Que- Which language can use inheritance with local classes? 

a. Kotlin 

b. Java 

c. SmallTalk 

d. SAP ABAP 


Ans- SAP ABAP  


Que- 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 


Ans- As many as required  


Que- 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 


Ans- Defined in constructor  


Que- 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 arises 


Ans- Yes, since local  


Que- 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 


Ans- Within the function  


Que- 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 


Ans- No, can't access  


Que- Which among the following is 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 


Ans- Helps to add extra functionality to a function  


Que- 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 structure 


Ans- Class inside a class  


Que- Which feature of OOP reduces the use of nested classes? 

a. Encapsulation 

b. Inheritance 

c. Binding 

d. Abstraction 


Ans- Inheritance  


Que- How many categories are nested classes divided into? 

a. 2 

b. 3 

c. 4 

d. 5 


Ans- 2  


Que- Non-static nested classes have access to _____________ from enclosing class. 

a. Private members 

b. Protected members 

c. Public members 

d. All the members 


Ans- All the members  


Que- Static nested classes doesn't have access to _________________ from enclosing class. 

a. Private members 

b. Protected members 

c. Public members 

d. Any other members 


Ans- Any other members  


Que- The nested class can be declared ___________________ 

a. Public 

b. Private 

c. Protected 

d. Public, Protected, Private or Package private 


Ans- Public, Protected, Private or Package private  


Que- Use of nested class ____________ encapsulation. 

a. Increases 

b. Decreases 

c. Doesn't affect 

d. Slightly decreases 


Ans- Increases  


Que- Which among the following is 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 


Ans- Makes the code efficient and readable  


Que- How to access static nested classes? 

a. OuterClass.StaticNestedClass 

b. OuterClass->StaticNestedClass 

c. OuterClass(StaticNestedClass) 

d. OuterClass[StaticNestedClass]. 


Ans- OuterClass.StaticNestedClass  


Que- 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(); 


Ans- OuterClass.InnerClass innerObject = outerObject.new InnerClass();  


Que- Instance of inner class can exist only _______________ enclosing class. 

a. Within 

b. Outside 

c. Private to 

d. Public to 


Ans- Within  


Que- 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 


Ans- Inner declaration shadows outer declaration in  


Que- 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 


Ans- Top level, top level  


Que- In how many ways can an object be passed to a function? 

a. 1 

b. 2 

c. 3 

d. 4 


Ans- 3  


Que- 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 


Ans- A new copy of object is created implicitly  


Que- 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 


Ans- Explicitly, Implicitly  


Que- 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 


Ans- Are reflected to the main object of caller function too  


Que- 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 


Ans- Yes, must be called  


Que- 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 


Ans- Temporary object  


Que- 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 


Ans- No, unexpected side effects may occur  


Que- 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 


Ans- Overloading assignment operator and defining copy constructor  


Que- How many objects can be returned at once? 

a. Only 1 

b. Only 2 

c. Only 16 

d. As many as required 


Ans- Only 1  


Que- 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 


Ans- No, the changes are made automatically  


Que- 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 


Ans- As many as required  


Que- 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 


Ans- No, values are copied  


Que- 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 


Ans- No, Duplicate declaration is not allowed  


Que- 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 


Ans- It is address of where the variables and methods of object are stored  


Que- 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 


Ans- Actually the objects aren't used  


Previous Post Next Post

Responsive Ad