Object Oriented Programming interview questions part 37
Object Oriented Programming interview questions part 37
Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. In how many ways can an object be passed to a function?
Correct Answer is : 3
2. If an object is passed by value, ____________________
Correct Answer is : A new copy of object is created implicitly
3. Pass by address passes the address of object _________ and pass by reference passes the address of the object _________
Correct Answer is : Explicitly, Implicitly
4. If an object is passed by reference, the changes made in the function ___________
Correct Answer is : Are reflected to the main object of caller function too
5. Constructor function is not called when an object is passed to a function, will its destructor be called when its copy is destroyed?
Correct Answer is : Yes, must be called
6. When an object is returned by a function, a _______________ is automatically created to hold the return value.
Correct Answer is : Temporary object
7. Is the destruction of temporary object safe (while returning object)?
Correct Answer is : No, unexpected side effects may occur
8. How to overcome the problem arising due to destruction of temporary object?
Correct Answer is : Overloading assignment operator and defining copy constructor
9. How many objects can be returned at once?
Correct Answer is : Only 1
10. What will be the output of the following code?
Class A
{
int i;
public : A(int n)
{
i=n; cout<<”inside constructor ”;
}
~A()
{
cout<<”destroying ”<<i;
}
void seti(int n)
{
i=n;
}
int geti()
{
return I;
}
};
void t(A ob)
{
cout<<”something ”;
}
int main()
{
A a(1);
t(a);
cout<<”this is i in main ”;
cout<<a.geti();
}
Correct Answer is : inside constructor something destroying 2this is i in main destroying 1
11. It is necessary to return the object if it was passed by reference to a function.
Correct Answer is : No, the changes are made automatically
12. How many objects can be passed to a function simultaneously?
Correct Answer is : As many as required
13. If an object is passed by address, will be constructor be called?
Correct Answer is : No, values are copied
14. Is it possible that an object of is passed to a function, and the function also have an object of same name?
Correct Answer is : No, Duplicate declaration is not allowed
15. Passing an object using copy constructor and pass by value are same.
Correct Answer is : FALSE
16. Passing object to a function _______________
Correct Answer is : Can be done in more than one ways
17. The object ________________
Correct Answer is : Can be passed by reference or value
18. Which symbol should be used to pass the object by reference in C++?
Correct Answer is : &
19. If object is passed by value, ________________
Correct Answer is : Copy constructor is used to copy the values into another object in the function
20. Pass by reference of an object to a function _______________
Correct Answer is : Affects the object in caller function