Escolar Documentos
Profissional Documentos
Cultura Documentos
sanfoundry.com
Answer: b
Explanation: The objects can be passed to the functions
and this requires OOP concept because objects are main
part of OOP. The objects can be passed in more than one
way to a function. The passing depends on how the object
have to be used.
1 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The objects can be passed by reference if
required to use the same object. The values can be passed
so that the main object remains same and no changes are
made to it if the function makes any changes to the values
being passed.
Answer: a
Explanation: The object to be passed by reference to the
function should be preceded by & symbol in the argument
list syntax of the function. This indicates the compiler not to
use new object. The same object which is being passed
have to be used.
2 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The copy constructor is used. This constructor
is used to copy the values into a new object which will
contain all the values same as that of the object being
passed but any changes made to the newly created object
will not affect the original object.
Answer: c
Explanation: The original object in the caller function will get
affected. The changes made in the called function will be
same in the caller function object also.
3 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The object must be passed by reference to a
copy constructor. This is to avoid the out of memory error.
The constructors keeps calling itself, if not passed by
reference, and goes out of memory.
Answer: d
Explanation: The type of object is the class itself. The class
name have to be specified in order to pass the objects to a
function. This allows the program to create another object
of same class or to use the same object that was passed.
Answer: b
Explanation: When an object is called by values, copy
constructor is called and object is copied to the local object
4 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: The data members can be passed with help of
object but only if the member is public. The object will
obviously be used outside the class. The object must have
access to the data member so that its value or reference is
used outside the class which is possible only if the member
is public.
Answer: c
Explanation: The location of the object, that is, the exact
memory location is passed, when the object is passed by
5 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The data members can be passed separately.
There is no need to pass whole object, instead we can use
the object to pass only the required values.
Answer: b
Explanation: There is no restriction on passing the number
of objects to a function. The operating system or the
compiler or environment may limit the number of
arguments. But there is no limit on number of objects till
that limit.
6 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: This is because the x object is passed by
reference. The changes made inside the function will be
applicable to original function too.
Answer: b
7 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: There is no condition which specifies that only
the reference pass or values pass is allowed. The argument
list ca contain one reference pass and another value pass.
This helps to manipulate the objects with functions more
easily.
8 of 8 3/19/18, 10:05 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: c
Explanation: The objects can be returned either by value or
reference. There is no mandatory condition for the way it
should be used. The way of returning object can be decided
based on the requirement.
1 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: A temporary object is created when an object
is returned by value. The temporary object is used to copy
the values to another object or to be used in some way. The
object holds all the values of the data members of the
object.
Answer: b
Explanation: The temporary object are created within the
function and are intended to return the value for specific
use. Either the object can be assigned to another object or
be used directly if possible.
2 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
View Answer
Answer: d
Explanation: The class name itself should be the return type
of the function. This notifies that the function will return an
object of specified class type. Only the class name should
be specified.
Answer: a
Explanation: The function declaration must contain the
class name as return type. But, a & symbol should be
followed by the class name. & indicates that the object
being returned will be returned by reference.
Answer: b
Explanation: The object which is declared inside the class
can never be returned by reference. This is because the
3 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: Only one object can be returned at a time.
This is because a function is only capable of returning a
single value at a time. Though array of objects can be
returned from a function.
Answer: c
Explanation: If the local object is returned outside the
function then the compile time error arises. While the
program is being converted and the processes happening
during compile time, the compiler won’t be able to resolve
4 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
the statement.
Answer: d
Explanation: The temporary object is not created. If object
is returned by reference, a particular memory location will
be denoted with another name and hence same address
values will be used.
Answer: b
Explanation: It is not mandatory to return the whole object.
Instead we can return a specific data member value. But
the return type given must match with the data type of the
data being returned.
5 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The Object array can be returned from a
function. This can be done by putting a className* as the
return type of the function. This makes the return type to
accept an array of objects in return.
Answer: b
Explanation: It is not compulsory to return the object in the
same way as it was passed. If the object is passed by
reference then there is actually no need to return the object.
Because the changes made inside the function will be
visible on the original object of caller function also.
Answer: a
6 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: When an object is returned by value, it will be
returned to another object or will be directly used. Still in all
the conditions the copy constructor will be used to copy all
the values from the temporary object that gets created.
Answer: c
Explanation: A reference to the memory location where the
7 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
8 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: b
Explanation: The values get copied to another object. No
address is assigned to the object values. This is uses copy
constructor to copy the values.
1 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: The new object created, refers to the same
address of the previously created object. Now whenever
new object changes any data member value, it will affect
the previously existing object.
Answer: a
Explanation: The arguments get initialized using the copy
constructor. There is need of assigning the value of all the
members of an object to the local object of the function.
class A
{
public int i;
};
void main()
{
A x;
A y=x;
x.i=10;
2 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
y.i=20;
y.i++;
y.i=20;
cout&l;<tx.i;
}
a) 10
b) 20
c) 21
d) 0
View Answer
Answer: b
Explanation: The expected output may be 10 because the
value of member of object x is printed. But when object x is
assigned to y, y points to the same address where x is
stored. So actually both objects x and y point to the same
location and refers to the same object.
Answer: c
Explanation: While defining a copy constructor, we use
reference const parameter, those are used for the
assignment. The assignment operator may or may not be
defined by the programmer, if not, compiler implicitly
3 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: Even if the programmer doesn’t define or even
if they define the copy constructor. The compiler still
generates a copy assignment operator. It doesn’t gets
suppressed.
Answer: b
Explanation: Only the non – const objects will be accepted
by the compiler. If a const object is passed, the compiler
produces an error. To reduce that, we use const argument
in definition, so that both const and non – const objects are
accepted.
4 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
d) As many as required
View Answer
Answer: d
Explanation: The memory address can be referenced by
more than one object. There is no maximum number
defined. Any number of objects can reference to the same
address.
Answer: a
Explanation: The assignment operator if used at declaration
then it uses copy constructor for the copying of objects. If
used in simple assignment syntax then it uses copy
assignment function.
10. If more than one object refer to the same address, any
changes made
a) Can be made visible to specific objects
b) Will be specific to one object only
c) From any object will be visible in all
d) Doesn’t changes the values of all objects
View Answer
Answer: c
5 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
11. How to make more than one object refer to the same
object?
a) Initialize it to null
b) Initialize the object with another at declaration
c) Use constructor to create new object
d) Assign the address directly
View Answer
Answer: b
Explanation: The object must get initialized with another
object at time of declaration only. We don’t have to create a
new object we just have to get name of new object because
there after same address will be referred.
Answer: a
Explanation: Only the reference value can be assigned to
another reference value. This is because both deal with the
address. There is no type mismatch hence we can assign
them.
6 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
Answer: c
Explanation: When an object is assigned with another
object. Same memory location is used. There is no other
copy of the object created.
Answer: d
Explanation: The direct assignment can be used with the
same class objects. There is no restriction on them. But
better if the program have a predefined copy assignment
operator.
Answer: b
Explanation: The actual assignment doesn’t take place as
7 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...
8 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: b
Explanation: The concept of pointers is not supported in
Java. The feature is not given in the language but can be
used in some ways explicitly. Though this pointer is
supported by java too.
1 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
d) className objectName();
View Answer
Answer: a
Explanation: The syntax must contain * symbol after the
className as the type of object. This declares an object
pointer. This can store address of any object of the
specified class.
Answer: d
Explanation: The members can be accessed from the
object pointer by using arrow operator. The arrow operator
can be used only with the pointer of class type. If simple
object is declared, it must use dot operator to access the
members.
Answer: c
2 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: The address of only the specified class type
can get their address stored in the object pointer. The
addresses doesn’t differ but they do differ for the amount
and type of memory required for objects of different
classes. Hence same class object pointer should be used.
Answer: a
Explanation: The size of object pointer is same as that of
any usual pointer. This is because only the address have to
be stored. There are no values to be stored in the pointer.
7. A pointer _________________
3 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The object pointer can point to only one object
at a time. The pointer will be able to store only one address
at a time. Hence only one object can be referred.
Answer: a
Explanation: It is an implicit rule defined in most of the
programming languages. It permits the programmer to
declare a pointer to the derived class from a base class
pointer. In this way the programmer doesn’t have to declare
object for derived class each time it is required.
4 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
d) No, never
View Answer
Answer: d
Explanation: The pointers to an object can never access the
private members of the class outside the class. The object
can indirectly use those private members using member
functions which are public in the class.
Answer: a
Explanation: The array name represents a pointer to the
object. The name alone can represent the starting address
of the array. But that also represents an array which is in
turn stored in a pointer.
Answer: a
Explanation: The pointer to an object can hold only the
addresses. Address of any other object of same class. This
allows the programmer to link more than one objects if
5 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
required.
Answer: a
Explanation: The pointer should be mentioned followed by
the arrow operator. Arrow operator is applicable only with
the pointers. Then the function name should be mentioned
that is to be called.
Answer: b
Explanation: When the address pointed by the object
pointer gets deleted, the pointer now points to an invalid
address. Hence it becomes a dangling pointer. It can’t be
null or void pointer since it doesn’t point to any specific
location.
6 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
b) Using $ symbol
c) Using & symbol
d) Using @ symbol
View Answer
Answer: c
Explanation: The & symbol must be used. This should be
done such that the object should be preceded by & symbol
and then the address should be stored in another variable.
This is done to get the address where the object is stored.
Answer: d
Explanation: The pointer should be declared as a const
type. This prevents the pointer to change any value that is
being pointed from it. This is a feature that is made to
access the values using pointer but to make sure that
pointer doesn’t change those values accidently.
Answer: b
Explanation: The references are made to object when the
7 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...
8 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
sanfoundry.com
Answer: b
Explanation: The pointer which denotes the object calling
the member function is known as this pointer. The this
pointer is usually used when there are members in the
function with same name as those of the class members.
1 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
are called
b) this pointer is passed explicitly when member functions
are called
c) this pointer is passed with help of pointer member
functions are called
d) this pointer is passed with help of void pointer member
functions are called
View Answer
Answer: a
Explanation: When an object calls some member function, it
implicitly passes itself as an argument. This allows the
compiler to know which member should be used for the
purposes. This also allows to reduce the ambiguity among
the variable and data member names.
Answer: c
Explanation: The this pointer is available only within the
non-static member functions of a class. If the member
function is static, it will be common to all the objects and
hence a single object can’t refer to those functions
independently.
2 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: The object’s this pointer being called are not
part of the object itself. This can be cross verified by
checking that it doesn’t take up any space for the data to be
stored or pointed.
Answer: c
Explanation: The space taken by this pointer is not reflected
in by the sizeof() operator. This is because object’s this
pointer is not part of object itself. This is a cross verification
for the concept stating that this pointer doesn’t take any
space in the object.
3 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
Answer: a
Explanation: The address is passed implicitly as an
argument to the function. This doesn’t have to be passed
explicitly. The address is passed, of the object which is
calling the non-static member function.
Answer: d
Explanation: The function name is specified first and then
the parameter lists. The parameter list is included with the
object name along with & symbol. This denotes that the
address of the object is being passed as an argument.
Answer: c
Explanation: The address of the object with respect to
4 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
Answer: b
Explanation: The this pointer can be used to guard itself
whenever self-reference is used. This allows accidental
address access. And accidental modification of data.
Answer: a
Explanation: The condition becomes false when executed
and hence doesn’t executes. This is the case where this
pointer can guard itself from the self-reference. Here if the
address of the object doesn’t match with this pointer that
means the object doesn’t refer itself.
5 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
Answer: d
Explanation: The this pointer is non modifiable. This is
because the address of any object remains constant
throughout its life time. Hence the address must not be
changed otherwise wrong members of invalid addresses
might get accessed.
Answer: c
Explanation: The earlier, most initial versions of C++ used
to allow assignments to this pointers. That used to allow
modifications of this pointer. Later that feature got disabled.
6 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
View Answer
Answer: a
Explanation: This is a feature provided, that can be used
directly. The manipulation of self-referential data structures
is just an application of this feature. Other conditions fails
as this pointer doesn’t deal with those things.
Answer: c
Explanation: The this pointer can be declared const or
volatile. This depends on need of program and type of
code. This is just an additional feature.
Answer: d
Explanation: The syntax contains the cv-qualifier-list that
can be determined from the member function declaratory
that can be either const or volatile or can be made both.
Hence we write it as list. classType denotes the name of
7 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...
8 of 8 3/19/18, 10:06 AM