Object Oriented Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Object Oriented Programming MCQ (Multiple Choice Questions)

 Que- Which specifier allows a programmer to make the private members which can be inherited? 

a. Private 

b. Default 

c. Protected 

d. Protected and default 


Ans- Protected  


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


Ans- Default members can't be inherited  


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


Ans- Public  


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


Ans- Private, protected and public members of class A  


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


Ans- All private constructors  


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


Ans- All the data members are added  


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

d. No, because friend function can access private member of class A also 


Ans- No, because friend function can only access private members of friend class  


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


Ans- No class will be able to implement members of abstract class  


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


Ans- Public  


Que- Which access specifier is usually used for data members of a class? 

a. Private 

b. Default 

c. Protected 

d. Public 


Ans- Private  


Que- Which specifier should be used for member functions of a class? 

a. Private 

b. Default 

c. Protected 

d. Public 


Ans- Public  


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


Ans- Private  


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


Ans- Not possible  


Que- If private members has 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 


Ans- Friend function should be used  


Que- Which access specifier is/are most secure during inheritance? 

a. Private 

b. Default 

c. Protected 

d. Private and default 


Ans- Private  


Que- Choose the correct option for the code given belowclass 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 


Ans- Constructor will keep number of objects created  


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


Ans- Private member function can't be overridden  


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


Ans- Private specifier can be used anywhere in class  


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


Ans- Members are secure as private, but can be inherited  


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


Ans- It's instance can be created inside the subclasses  


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


Ans- The sub class should inherit the parent class privately  


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


Ans- Protected members can be accessed outside package using inheritance, but default can't  


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


Ans- Instance of class can be created anywhere  


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


Ans- Protected and Public members become protected in subclass  


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


Ans- Members must be made public  


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


Ans- Members which have to be secure and should be used by other packages/subclass  


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


Ans- Define a constructor in public access with different signature  


Que- If the members have to be accessed from anywhere in program and other packages also, which access specifier should be used? 

a. Public 

b. Private 

c. Protected 

d. Default 


Ans- Public  


Que- Which among the following have least security according to the access permissions allowed? 

a. Private 

b. Default 

c. Protected 

d. Public 


Ans- Public  


Que- Which among the following can be used for outermost class access specifier in java? 

a. Private 

b. Public 

c. Default 

d. Default or Public 


Ans- Default or Public  


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


Ans- All those will be available in subclasses  


Que- How many public class(s) (outermost) can be there in a java program? 

a. 1 

b. 2 

c. 3 

d. As required 


Ans- 1  


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


Ans- The static members can't be public  


Que- A class has its default constructor defined as publi

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


Ans- Both classes can have instances  


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


Ans- Public  


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


Ans- Public classes can be accessed from any other class using instance  


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


Ans- None of its member function can be called outside the class  


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


Ans- Will continue to get inherited subsequently  


Que- Which specifier allows to secure the public members of base class in inherited classes? 

a. Private 

b. Protected 

c. Public 

d. Private and Protected 


Ans- Private and Protected  


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


Ans- Data members  


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


Ans- Can be initialized only with help of constructors  


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


Ans- Static data members are defined outside class, not in constructor  


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


Ans- The structure must have been defined before class.  


Que- How many data members can a class contain? 

a. 27 

b. 255 

c. 1024 

d. As many as required 


Ans- As many as required  


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


Ans- Dot or arrow as required  


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


Ans- Return the address of the private data member using a member function  


Previous Post Next Post