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. |
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 castingI had been asked this question in homework.My doubt stems from Downcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (b) Because inheritance follows is-a relationship |
|
| 2. |
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 inheritanceI have been asked this question during a job interview.I'm obligated to ask this question of Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right choice is (c) To compare two objects |
|
| 3. |
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 errorI had been asked this question in an interview for job.Asked question is from Downcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct choice is (a) Compile time error |
|
| 4. |
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 matterI have been asked this question in homework.I'd like to ask this question from Downcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right choice is (b) DOWNWARD the inheritance order |
|
| 5. |
Java supports direct downcasting.(a) True(b) FalseThis question was addressed to me in unit test.The origin of the question is Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct option is (b) False |
|
| 6. |
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 conversionI have been asked this question during an interview.The above asked question is from Downcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right CHOICE is (a) By using INSTANCEOF |
|
| 7. |
Which is the exception handler for the exceptions of downcasting?(a) CastException(b) ClassCastingExeption(c) ClassCasting(d) ClassCastExceptionThe question was asked during an online interview.Enquiry is from Downcasting topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT ANSWER is (d) ClassCastException Easy explanation - The exception handler for the exceptions PRODUCED during the DOWNCASTING exception. This handler can be called during runtime to handle any exception thrown. |
|
| 8. |
Which is the proper syntax of dynamic_cast?(a) dynamic_cast(object)(b) dynamic_cast new (object)(c) dynamic_cast(object)(d) dynamic_cast(object)This question was addressed to me in my homework.Question is from Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The correct CHOICE is (c) dynamic_cast(object) |
|
| 9. |
If dynamic_cast fails, which value is returned?(a) void(b) null(c) void pointer(d) null pointerI had been asked this question in an internship interview.This key question is from Downcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right answer is (d) null pointer |
|
| 10. |
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 addressI had been asked this question during an interview for a job.My question comes from Downcasting topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The correct answer is (a) Address of OBJECT which is CONVERTED |
|
| 11. |
What should be used for safe downcast?(a) Static cast(b) Dynamic cast(c) Manual cast(d) Implicit castThe question was asked in an online quiz.This key question is from Downcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct option is (b) Dynamic cast |
|
| 12. |
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 errorI have been asked this question during an interview for a job.The query is from Downcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT OPTION is (a) Can result in unexpected results To explain: 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. |
|
| 13. |
Downcasting is _______________________(a) Always safe(b) Never safe(c) Safe sometimes(d) Safe, depending on codeI had been asked this question during an interview.This question is from Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right choice is (b) Never safe |
|
| 14. |
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 explicitlyThe question was asked in my homework.This intriguing question comes from Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right OPTION is (c) It must be DONE explicitly |
|
| 15. |
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 typeI got this question in exam.My query is from Downcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right OPTION is (b) Casting supertype to subtype |
|
| 16. |
Which among the following is true?(a) Upcasting is possible only for single level inheritance(b) Upcasting is possible only for multilevel inheritance(c) Upcasting is possible only for multiple inheritance(d) Upcasting is possible for any type of inheritanceI had been asked this question in my homework.The query is from Upcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The correct option is (d) UPCASTING is possible for any TYPE of inheritance |
|
| 17. |
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();The question was asked by my school principal while I was bunking the class.My question is from Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» CORRECT CHOICE is (c) Parent *p=&child; Easy 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. |
|
| 18. |
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 directlyI got this question in exam.This intriguing question originated from Upcasting topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT option is (b) Runtime Best 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. |
|
| 19. |
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 typesThis question was addressed to me by my school teacher while I was bunking the class.My doubt is from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The CORRECT option is (a) Compile time |
|
| 20. |
Which concept is needed because of implicit type casting use?(a) Static binding(b) Dynamic binding(c) Compile time binding(d) Source code bindingI had been asked this question by my college professor while I was bunking the class.Origin of the question is Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (b) Dynamic binding |
|
| 21. |
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 allowedI got this question in a national level competition.I'm obligated to ask this question of Upcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right ANSWER is (a) ALWAYS allowed for public inheritance |
|
| 22. |
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 upcastedThis question was addressed to me in a national level competition.My doubt stems from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT OPTION is (c) Class C OBJECT can be upcasted to object of EITHER class A or B The explanation is: 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. |
|
| 23. |
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 possibleThe question was asked in final exam.This question is from Upcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right answer is (C) Upcast to any BASE CLASS |
|
| 24. |
Upcasting and downcasting objects are the same as casting primitive types.(a) True(b) FalseThe question was posed to me in my homework.My query is from Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (b) False |
|
| 25. |
Which property is shown most when upcasting is used?(a) Code reusability(b) Code efficiency(c) Complex code simple syntax(d) EncapsulationThis question was addressed to me in final exam.The query is from Upcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (c) Complex code simple syntax |
|
| 26. |
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 subtypeThe question was posed to me in an interview for job.This is a very interesting question from Upcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right answer is (b) For general code DEALING with only supertype |
|
| 27. |
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 versaI have been asked this question in unit test.Asked question is from Upcasting in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (a) UPCASTING |
|
| 28. |
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 inheritanceThe question was posed to me in quiz.My question comes from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right answer is (b) UPWARD to the INHERITANCE tree |
|
| 29. |
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 typeThis question was addressed to me by my college professor while I was bunking the class.This interesting question is from Upcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (a) CASTING subtype to supertype |
|
| 30. |
Which is a good alternative instead of having one zero argument constructor and one single argument constructor with default argument?(a) No constructor defined(b) One default value constructor(c) Defining the default constructor(d) Using one constructor with two argumentsThis question was posed to me by my college professor while I was bunking the class.My doubt is from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct ANSWER is (B) One default VALUE constructor |
|
| 31. |
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 argumentsThis question was addressed to me in semester exam.The origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT option is (d) The constructors with zero ARGUMENTS The EXPLANATION is: 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. |
|
| 32. |
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 errorThis question was posed to me in homework.I need to ask this question from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT answer is (C) Then all the default values GIVEN will be used Best 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. |
|
| 33. |
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);I have been asked this question by my college director while I was bunking the class.Enquiry is from Constructors Overloading in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct answer is (c) className(INT x=0,char c); |
|
| 34. |
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);(d) char className(char c,int x);I got this question by my school principal while I was bunking the class.The origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct answer is (a) className(int x=5,CHAR c=’a’); |
|
| 35. |
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 classThe question was asked in an international level competition.My doubt is from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT choice is (d) More than one constructors with all default arguments can’t EXIST in same class For 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. |
|
| 36. |
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 argumentsI have been asked this question in an interview for job.My enquiry is from Constructors Overloading in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT option is (a) The CONSTRUCTORS might have all the same arguments except the default arguments The best 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. |
|
| 37. |
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()This question was posed to me in unit test.I want to ask this question from Constructors Overloading in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT answer is (c) constructorName(INT x=0) To explain I would say: 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. |
|
| 38. |
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, neverThis question was addressed to me by my college professor while I was bunking the class.I'm obligated to ask this question of Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (d) No, never |
|
| 39. |
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)I got this question by my school principal while I was bunking the class.This intriguing question originated from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The CORRECT answer is (B) CONSTRUCTORNAME(int x=0, int y=0) |
|
| 40. |
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 classThis question was posed to me during an interview.Origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct option is (d) The constructors MUST have the same name as that of class |
|
| 41. |
The Constructors with all the default arguments are similar as default constructors.(a) True(b) FalseI have been asked this question in homework.I'd like to ask this question from Constructors Overloading topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» CORRECT choice is (a) True The 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. |
|
| 42. |
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 constructorI had been asked this question in homework.My enquiry is from Constructors Overloading topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct OPTION is (C) Use constructor with all default arguments |
|
| 43. |
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 typesI have been asked this question during an interview.My question is based upon Constructors Overloading in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (B) Constructors can be overloaded USING different SIGNATURES |
|
| 44. |
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 classesI got this question in an interview.I want to ask this question from Default Arguments topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right option is (a) Do not acquire base class declaration of default arguments |
|
| 45. |
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 callI had been asked this question in class test.This is a very interesting question from Default Arguments topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The correct choice is (d) But are executed during FUNCTION call |
|
| 46. |
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 feasibilityThis question was posed to me in an internship interview.This intriguing question comes from Default Arguments in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» RIGHT ANSWER is (C) Checked for accessibility To EXPLAIN I would say: 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. |
|
| 47. |
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 argumentsI got this question during an interview.Asked question is from Default Arguments topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right choice is (B) Carries over the known DEFAULT arguments |
|
| 48. |
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 programThe question was asked during an online exam.Question is taken from Default Arguments topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Right answer is (a) If and only if the function is declared again in the same scope |
|
| 49. |
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 declarationI have been asked this question in exam.My question is based upon Default Arguments topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» Correct choice is (d) Those are allowed with pointer and reference to function declaration |
|
| 50. |
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 valuesI have been asked this question in a job interview.My doubt is from Default Arguments topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming |
|
Answer» The CORRECT option is (a) Only allowed in the parameter list of the FUNCTION declaration |
|