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. |
How many types of access specifiers are provided in OOP (C++)?(a) 1(b) 2(c) 3(d) 4The question was posed to me in an online quiz.This intriguing question comes from Access Specifiers topic in division Access Specifiers of Object Oriented Programming |
|
Answer» RIGHT answer is (c) 3 For 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. |
|
| 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 togetherThis question was addressed to me during an online exam.I'm obligated to ask this question of Access Specifiers topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» The correct OPTION is (d) All THREE together |
|
| 3. |
Which among the following can restrict class members to get inherited?(a) Private(b) Protected(c) Public(d) All threeThe question was posed to me in an internship interview.My doubt stems from Access Specifiers in division Access Specifiers of Object Oriented Programming |
|
Answer» The correct option is (a) Private |
|
| 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) PublicThis question was posed to me during an online interview.Enquiry is from Access Specifiers in chapter Access Specifiers of Object Oriented Programming |
|
Answer» The correct option is (b) DEFAULT |
|
| 5. |
Which specifier allows a programmer to make the private members which can be inherited?(a) Private(b) Default(c) Protected(d) Protected and defaultI got this question during an interview.My query is from Access Specifiers in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Right choice is (C) PROTECTED |
|
| 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 alsoThe question was posed to me in unit test.My doubt is from Access Specifiers topic in section Access Specifiers of Object Oriented Programming |
|
Answer» The correct CHOICE is (c) Default members can’t be inherited |
|
| 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) DefaultI had been asked this question in homework.My question is from Access Specifiers in portion Access Specifiers of Object Oriented Programming |
|
Answer» Correct option is (B) Public |
|
| 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 AThe question was asked at a job interview.Question is from Access Specifiers topic in section Access Specifiers of Object Oriented Programming |
|
Answer» The CORRECT CHOICE is (d) Private, protected and PUBLIC members of class A |
|
| 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 protectedThe question was asked during an online exam.The query is from Access Specifiers topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Right OPTION is (b) All private constructors |
|
| 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 addedI have been asked this question in examination.This intriguing question comes from Access Specifiers in section Access Specifiers of Object Oriented Programming |
|
Answer» Correct answer is (a) All the data members are 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(d) No, because friend function can access private member of class A alsoI had been asked this question by my school principal while I was bunking the class.I want to ask this question from Access Specifiers topic in division Access Specifiers of Object Oriented Programming |
|
Answer» RIGHT answer is (C) No, because friend function can only access private members of friend class The 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.I have been asked this question during an interview.The query is from Access Specifiers in division Access Specifiers of Object Oriented Programming |
|
Answer» CORRECT answer is (a) No class will be able to implement members of abstract class 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) PublicThis question was addressed to me in a job interview.My query is from Access Specifiers topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Correct answer is (d) Public |
|
| 14. |
Which access specifier is usually used for data members of a class?(a) Private(b) Default(c) Protected(d) PublicThe question was posed to me during an online exam.The origin of the question is Access Specifiers topic in section Access Specifiers of Object Oriented Programming |
|
Answer» Correct choice is (a) Private |
|
| 15. |
Which specifier should be used for member functions of a class?(a) Private(b) Default(c) Protected(d) PublicI had been asked this question during an internship interview.The origin of the question is Access Specifiers in section Access Specifiers of Object Oriented Programming |
|
Answer» RIGHT option is (d) PUBLIC 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. |
|
| 16. |
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) DefaultI got this question in an interview for internship.Origin of the question is Private Access Specifier topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Right option is (a) PRIVATE |
|
| 17. |
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 possibleI have been asked this question by my school teacher while I was bunking the class.Question is from Private Access Specifier in chapter Access Specifiers of Object Oriented Programming |
|
Answer» The correct choice is (d) Not possible |
|
| 18. |
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 possibleThe question was asked by my school principal while I was bunking the class.This is a very interesting question from Private Access Specifier topic in section Access Specifiers of Object Oriented Programming |
|
Answer» Correct answer is (b) Friend function should be used |
|
| 19. |
Which access specifier is/are most secure during inheritance?(a) Private(b) Default(c) Protected(d) Private and defaultI had been asked this question by my school principal while I was bunking the class.Origin of the question is Private Access Specifier in portion Access Specifiers of Object Oriented Programming |
|
Answer» RIGHT choice is (a) Private Easiest 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. |
|
| 20. |
Private member functions can be overloaded.(a) True(b) FalseI have been asked this question during an interview for a job.My question is from Private Access Specifier topic in portion Access Specifiers of Object Oriented Programming |
|
Answer» Right answer is (a) True |
|
| 21. |
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 memberfunction can’t be overriddenI had been asked this question in semester exam.Question is from Private Access Specifier topic in division Access Specifiers of Object Oriented Programming |
|
Answer» The correct option is (d) Private memberfunction can’t be OVERRIDDEN |
|
| 22. |
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 classI got this question in an internship interview.I need to ask this question from Private Access Specifier in portion Access Specifiers of Object Oriented Programming |
|
Answer» Correct CHOICE is (d) PRIVATE specifier can be used ANYWHERE in class |
|
| 23. |
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 inheritedThe question was asked in an online interview.My question is from Protected Access Specifier topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» The correct option is (c) MEMBERS are secure as private, but can be inherited |
|
| 24. |
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 onlyI have been asked this question in an interview for internship.I need to ask this question from Protected Access Specifier topic in section Access Specifiers of Object Oriented Programming |
|
Answer» Right option is (a) It’s instance can be created INSIDE the subclasses |
|
| 25. |
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 modifierThe question was posed to me in an interview for job.Origin of the question is Protected Access Specifier in chapter Access Specifiers of Object Oriented Programming |
|
Answer» The CORRECT choice is (a) The sub class should INHERIT the parent class privately |
|
| 26. |
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 sameI have been asked this question in an online quiz.My question is based upon Protected Access Specifier topic in portion Access Specifiers of Object Oriented Programming |
|
Answer» Correct choice is (a) Protected members can be accessed outside package USING INHERITANCE, but default can’t |
|
| 27. |
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() functionI have been asked this question in an internship interview.This key question is from Protected Access Specifier in division Access Specifiers of Object Oriented Programming |
|
Answer» The correct CHOICE is (b) Instance of CLASS can be created anywhere |
|
| 28. |
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 subclassThe question was asked during a job interview.Question is from Protected Access Specifier topic in section Access Specifiers of Object Oriented Programming |
|
Answer» The correct ANSWER is (d) Protected and Public MEMBERS become protected in subclass |
|
| 29. |
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 publicThe question was posed to me during an online interview.Origin of the question is Protected Access Specifier topic in portion Access Specifiers of Object Oriented Programming |
|
Answer» Right option is (d) MEMBERS MUST be made public |
|
| 30. |
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() functionI got this question in class test.This interesting question is from Protected Access Specifier in division Access Specifiers of Object Oriented Programming |
|
Answer» Right answer is (b) Members which have to be SECURE and should be USED by other packages/subclass |
|
| 31. |
Protected access is same as default access that is given implicitly in java if no specifier is mentioned.(a) True(b) FalseI had been asked this question in an online quiz.Query is from Protected Access Specifier in section Access Specifiers of Object Oriented Programming |
|
Answer» The correct OPTION is (b) False |
|
| 32. |
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 possibleThis question was addressed to me in my homework.My doubt stems from Protected Access Specifier topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Right OPTION is (a) DEFINE a CONSTRUCTOR in public access with different signature |
|
| 33. |
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) DefaultI had been asked this question in an interview for job.Question is from Public Access Specifier in portion Access Specifiers of Object Oriented Programming |
|
Answer» The correct choice is (a) Public |
|
| 34. |
Which among the following have least security according to the access permissions allowed?(a) Private(b) Default(c) Protected(d) PublicThis question was addressed to me in exam.Origin of the question is Public Access Specifier topic in division Access Specifiers of Object Oriented Programming |
|
Answer» Correct ANSWER is (d) PUBLIC |
|
| 35. |
Which among the following can be used for outermost class access specifier in java?(a) Private(b) Public(c) Default(d) Default or PublicI got this question by my school teacher while I was bunking the class.I need to ask this question from Public Access Specifier topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» CORRECT choice is (d) Default or Public The 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. |
|
| 36. |
We can reduce the visibility of inherited methods.(a) True(b) FalseI had been asked this question in semester exam.The origin of the question is Public Access Specifier in division Access Specifiers of Object Oriented Programming |
|
Answer» Correct option is (B) False |
|
| 37. |
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 subclassI had been asked this question in an online interview.I'd like to ask this question from Public Access Specifier topic in section Access Specifiers of Object Oriented Programming |
|
Answer» Correct choice is (a) All those will be AVAILABLE in subclasses |
|
| 38. |
How many public class(s) (outermost) can be there in a java program?(a) 1(b) 2(c) 3(d) As requiredThe question was posed to me in exam.My question is taken from Public Access Specifier in chapter Access Specifiers of Object Oriented Programming |
|
Answer» The correct choice is (a) 1 |
|
| 39. |
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 programThe question was posed to me in quiz.I'm obligated to ask this question of Public Access Specifier in section Access Specifiers of Object Oriented Programming |
|
Answer» The correct CHOICE is (a) The static MEMBERS can’t be PUBLIC |
|
| 40. |
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 instancesThe question was posed to me in an interview.The question is from Public Access Specifier topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Correct answer is (d) Both classes can have INSTANCES |
|
| 41. |
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) ProtectedThis question was addressed to me in an international level competition.This interesting question is from Public Access Specifier topic in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Right ANSWER is (c) Public |
|
| 42. |
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 instanceI got this question in homework.I want to ask this question from Public Access Specifier in chapter Access Specifiers of Object Oriented Programming |
|
Answer» Right option is (d) Public classes can be accessed from any other class USING INSTANCE |
|
| 43. |
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 valueI had been asked this question at a job interview.My doubt stems from Public Access Specifier in division Access Specifiers of Object Oriented Programming |
|
Answer» The correct option is (c) None of its member function can be called outside the class |
|
| 44. |
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 spaceThe question was asked in my homework.My doubt is from Public Access Specifier topic in portion Access Specifiers of Object Oriented Programming |
|
Answer» Correct OPTION is (a) Will continue to get inherited subsequently |
|
| 45. |
Which specifier allows to secure the public members of base class in inherited classes?(a) Private(b) Protected(c) Public(d) Private and ProtectedI got this question by my school teacher while I was bunking the class.My question comes from Public Access Specifier topic in division Access Specifiers of Object Oriented Programming |
|
Answer» The CORRECT choice is (d) Private and Protected |
|