Professional Documents
Culture Documents
c) Is not possible
View Answer
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.
View Answer
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.
a) &
b) @
c) $
d) $ or &
View Answer
Answer: a
advertisement
a) Copy constructor is used to copy the values into another object in the function
View Answer
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.
d) Affects the object only if mentioned with & symbol with every call
View Answer
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.
View Answer
Answer: c
7. What is the type of object that should be specified in the argument list?
a) Function name
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.
View Answer
Answer: b
Explanation: When an object is called by values, copy constructor is called and object is
copied to the local object of the function which is mentioned in the argument list. The
values gets copied and are used from the local object. There is no need to access the
original object again.
b) Yes, only if the data members are public and are being passed to a function outside the
class
View Answer
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.
View Answer
Answer: c
Explanation: The location of the object, that is, the exact memory location is passed,
when the object is passed by reference. The pass by reference is actually a reference to
the object that the function uses with another name to the same memory location as the
original object uses.
11. If the object is not to be passed to any function but the values of the object have to be
used then?
View Answer
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.
View Answer
Answer: b
13. What will be the output if all necessary code is included (Header files and main
function)?
c) Null
d) It is a string
View Answer
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.
View Answer
Answer: b
Explanation: The new memory location will be allocated only if the object is passed by
value. Reference uses the same memory address and is denoted by another name also.
But in pass by value, another object is created and new memory space is allocated for it.
15. Pass by reference and pass by value can’t be done simultaneously in a single function
argument list.
a) True
b) False
View Answer
Answer: b
Explanation: There is no condition which specifies that only the reference pass or values
pass is allowed. The argument list can contain one reference pass and another value
pass. This helps to manipulate the objects with functions more easily.
1. In which of the following way(s) can the object be returned from a function?
View Answer
Answer: c
View Answer
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.
3. Where the temporary objects (created while return by value) are created?
View Answer
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.
advertisement
a) void functionName ( ){ }
b) object functionName( ) { }
d) ClassName functionName ( ){ }
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.
5. Which is the correct syntax for defining a function which passes an object by reference?
a) className& functionName ( )
b) className* functionName( )
c) className-> functionName( )
d) &className functionName()
View Answer
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.
View Answer
Answer: b
Explanation: The object which is declared inside the class can never be returned by
reference. This is because the object will be destroyed as it goes out of scope when the
function is returned. The local variables get destroyed when function is returned hence
the local objects can’t be returned by reference.
7. How many independent objects can be returned at same time from a function?
a) 1
b) 2
c) 3
d) 4
View Answer
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.
8. Which error will be produced if a local object is returned by reference outside a function?
d) No error
View Answer
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 the statement.
9. If object is passed by reference ____________________
View Answer
Answer: d
View Answer
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.
a) Yes, always
b) Ye, only if objects are having same values
View Answer
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.
a) True
b) False
View Answer
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
View Answer
Answer: d
c) Because return by reference just make the objects points to values memory location
View Answer
Answer: c
Explanation: A reference to the memory location where the returned object is stored is
made. This allows the new object which takes the return value, point to the memory
location and hence access the same values.
View Answer
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.
View Answer
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.
3. How the argument passed to a function get initialized?
b) Copied directly
View Answer
Answer: a
Explanation: The arguments get initialized using the copy constructor. There is a need of
assigning the value of all the members of an object to the local object of the function.
advertisement
class A
public int i;
};
void main()
A x;
A y=x;
x.i=10;
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.
View Answer
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 defines member wise copy assignment operator.
a) True
b) False
View Answer
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.
7. In copy constructor definition, if non const values are accepted only ________
View Answer
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.
a) Only 1
b) At most 7
c) At most 3
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.
View Answer
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 __________
View Answer
Answer: c
Explanation: At a memory address, only one object can be referenced. All the other
objects which refer to the same memory address make changes for all of the objects
referring that address.
11. How to make more than one object refer to the same object?
a) Initialize it to null
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.
View Answer
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.
View Answer
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.
View Answer
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.
a) True
b) False
View Answer
Answer: b
Explanation: The actual assignment doesn’t take place as the object might have got
passed by reference. Also even if not by reference, the copy constructor is called to copy
the values into the new object and not exactly the assignment operator.
a) C++
b) Java
c) Pascal
d) C
View Answer
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.
a) className* objectName;
b) className objectName;
c) *className objectName;
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.
3. Which operator should be used to access the members of the class using object pointer?
a) Dot operator
d) Arrow operator
View Answer
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.
advertisement
4. How does compiler decide the intended object to be used, if more than one object are
used?
View Answer
Answer: c
Explanation: This pointer denotes the object, in which it is being used. If member function
is called with respect to one object then this pointer refers to the same object members. It
can be used when members with same name are involved.
View Answer
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.
6. What is the size of an object pointer?
View Answer
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 _________________
View Answer
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.
8. Pointer to a base class can be initialized with the address of derived class, because of
_________
View Answer
Answer: a
a) Yes, always
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.
a) Yes, always
d) No, never
View Answer
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.
View Answer
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
required.
12. Which is the correct syntax to call a member function using pointer?
a) pointer->function()
b) pointer.function()
c) pointer::function()
d) pointer:function()
View Answer
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.
13. If a pointer to an object is created and the object gets deleted without using the pointer
then __________
View Answer
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.
a) Using * symbol
b) 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.
15. What should be done to prevent changes that may be made to the values pointed by the
pointer?
View Answer
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.
a) True
b) False
View Answer
Answer: b
Explanation: The references are made to object when the object is created and initialized
with another object without calling any constructor. But the object pointer must be
declared explicitly using * symbol that will be capable of storing some address. Hence
both are different.
1. Which is the pointer which denotes the object calling the member function?
a) Variable pointer
b) This pointer
c) Null pointer
d) Zero pointer
View Answer
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.
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.
3. The this pointer is accessible __________________
View Answer
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.
advertisement
View Answer
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.
View Answer
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.
View Answer
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.
7. Which is the correct interpretation of the member function call from an object,
object.function(parameter);
a) object.function(&this, parameter)
b) object(&function,parameter)
c) function(&object,¶meter)
d) function(&object,parameter)
View Answer
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.
d) Can be accessed using the object name inside the member function
View Answer
Answer: c
Explanation: The address of the object with respect to which the member functions are
being called, are stored in this pointer. This pointer is hence used whenever there are
members with same name as those of the variables inside the function.
View Answer
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.
a) if(&object != this)
b) if(&function !=object)
c) this.if(!this)
d) this.function(!this)
View Answer
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.
a) Are modifiable
d) Are non-modifiable
View Answer
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.
View Answer
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.
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.
a) const
b) volatile
c) const or volatile
d) int
View Answer
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.
15. Which is the correct syntax for declaring the type of this in a member function?
View Answer
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 class to mention to which class
does the object belong to. And *const this denotes that the this pointer is having a
constant value.
View Answer
Answer: b
Explanation: The arguments which are assigned with some default value. Since some
value is already given, it is not mandatory to pass those arguments. They can be used
directly.
View Answer
Answer: a
Explanation: The default arguments must be declared at last in the argument list. This is
to ensure that the arguments doesn’t create ambiguity. The normal arguments should be
passed first.
3. If a member function have to be made both zero argument and parameterized
constructor, which among the following can be the best option?
View Answer
Answer: d
Explanation: All the arguments must be made default. This will make sure that none of
the arguments are mandatory to be passed. Which in turn means that the function can
work without any argument and can be passed with arguments too.
advertisement
b) void add(int=0)
d) void add(char c)
View Answer
Answer: c
Explanation: For the function to be called without arguments, either it must have zero
arguments or it must have all the default arguments. Here the function in option void
add(int x=0, int y=0) have all the default arguments and hence can be called directly with
zero argument.
5. If a function have all the default arguments but still some values are passed to the
function then ______________
b) The function will use the default values as those are local
View Answer
Answer: a
Explanation: The function will use the values passed explicitly to it. The default values will
be ignored. The default values are used only in case the values are not passed explicitly
to the function.
View Answer
Answer: c
Explanation: The default arguments must be mentioned at last in the argument list. Also,
the type of values assigned must match with the argument type. All the default arguments
must be mentioned at last, none of the normal arguments should come in between the
default arguments list.
View Answer
Answer: d
Explanation: There are three arguments that are getting passed to the function test().
Only the last option have all the default argument at last in the argument list. And the total
number of the arguments is three. The third option is wrong because the return type is int
and the syntax given is independent which means it doesn’t return any value.
8. Which among the following is a wrong call to the function void test(int x, int y=0, int z=0)?
a) test(5,6,7);
b) test(5);
c) test();
d) test(5,6);
View Answer
Answer: c
Explanation: The function must be passed with at least one argument. There is two
default arguments and one normal argument which must be passed with some value.
Hence the third call to the function is wrong as it doesn’t pass even a single parameter to
the function
View Answer
Answer: a
Explanation: The default arguments are only allowed in the parameter list of the function
arguments. This rule was not applicable in the beginning versions of c++ but later from
c++ 14th version it has been implemented. This is the only way to use default arguments.
View Answer
Answer: d
Explanation: The statements given are true because that is a feature given to make the
programming more flexible and have some security with accidental changes at same
time. The last option is false because it is not a rule defined. It is an opposite statement to
the rules defined for default arguments.
11. The non-template functions can be added with default arguments to already declared
functions ____________________
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
View Answer
Answer: a
Explanation: The non-template functions can also be added with default arguments. This
can be done even if the functions were defined earlier. This is because the call to the
function won’t be affected. The function can still be used in the same way as it was used
earlier.
View Answer
Answer: b
Explanation: The using-declaration carries over all the known default arguments. This is a
common feature as the usage doesn’t gets affected even if the default arguments are
added. This comes under flexible programming.
13. The names given to the default arguments are only looked up and ________________
and are bound during declaration.
View Answer
Answer: c
Explanation: 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.
View Answer
Answer: d
Explanation: The default argument are bound at the time of declaration. That is an implicit
functioning. But those are executed only when the function is called. Otherwise, those will
never get executed.
View Answer
Answer: a
Explanation: The virtual function overrides do not acquire the base class declaration of
default arguments. Even if a call to the virtual function is made, static type of the object
decides the default arguments to be used.
View Answer
Answer: b
Explanation: The constructors can be overloaded only if the definitions have different
signatures. Constructors doesn’t have any return type so can’t be overloaded using return
type. If constructors have same signature then it will produce a compile time error.
View Answer
Answer: c
Explanation: The constructor should use all the default arguments. This will allow the
constructor to be called even if no arguments are passed. And if arguments are passed,
those will be accepted instead of the default values.
3. The Constructors with all the default arguments are similar as default constructors.
a) True
b) False
View Answer
Answer: a
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.
advertisement
View Answer
Answer: d
Explanation: The constructors must have the same name as that of the class name. This
is mandatory because only the constructor functions doesn’t have any return type. Also,
for overloading all the functions must have the same name.
d) constructorName(int x, int y)
View Answer
Answer: b
6. Can a class have more than one function with all the default arguments?
a) Yes, always
d) No, never
View Answer
Answer: d
Explanation: A single class can never have more than once constructor with all the
default arguments. This is because it will make all those constructors as a default
constructor. And when an object is created with zero arguments then it will create
ambiguity.
7. Which is the correct syntax for using default arguments with the constructor?
c) constructorName(int x=0)
d) constructorName()
View Answer
Answer: c
Explanation: 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.
8. How many parameters must be passed if only the following prototype is given to a
constructor?
a) 1
b) 2
c) 3
View Answer
Answer: b
Explanation: In the prototype given, only 2 arguments are mandatory. Since the third
argument is default argument, so it is not mandatory to pass the argument.
9. 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
View Answer
Answer: a
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.
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 class
View Answer
Answer: d
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.
11. Which constructor among the following will be called if a call is made like
className(5,’a’);?
View Answer
Answer: a
Explanation: The syntax given is passing two parameters to the constructor call. One
value is of integer type and another of character type. Hence the constructor with
arguments of int and char type should be called. There is only one option that first
accepts integer value and then a character value. Hence that constructor will be called.
a) className(int x=0);
b) className(char c);
View Answer
Answer: c
Explanation: The default arguments, just like with member functions, must be listed at last
in the argument list. Hence this will produce a compile time error. The compiler doesn’t
allow the definition to be executed.
13. If there is a constructor with all the default arguments and arguments are not passed
then _________________
View Answer
Answer: c
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.
View Answer
Answer: d
15. Which is a good alternative instead of having one zero argument constructor and one
single argument constructor with default argument?
a) No constructor defined
Answer: b
Explanation: The constructor with one default argument can be the best alternative. This
is because the constructor with one default value will do the work for both the default
constructor and one argument constructor.
1. What is upcasting?
View Answer
Answer: a
Explanation: The upcasting concept includes only the casting of subtypes to the super
types. This casting is generally done implicitly. Smaller size types can fit into larger size
types implicitly.
View Answer
Answer: b
a) Upcasting
b) Downcasting
View Answer
Answer: a
Explanation: The upcasting is always safe since the derived type or the smaller type is
converted into the base type or the larger size. This results in allocating a smaller size
data into bigger type data. No data is lost in casting, hence safe.
advertisement
c) For general code dealing with both the supertype and subtype
View Answer
Answer: b
Explanation: When a general code has to be written where we use only the supertype
object or the data of bigger size, then upcasting would be the best option. Since the
whole code will require only the supertype name references.
a) Code reusability
b) Code efficiency
d) Encapsulation
View Answer
Answer: c
Explanation: The code written using upcasting mostly shows complex code in simpler
syntax features. This is because the upcasting concept can be applied as polymorphism
and to group the similar type of objects.
6. Upcasting and downcasting objects are the same as casting primitive types.
a) True
b) False
View Answer
Answer: b
Explanation: It is a bit confusing concept since both casting concepts are different.
Primitive casting depends on the type and size of data being typecast. Whereas in
objects casting, the classes and inheritance order plays a big role.
7. Which casting among the following is allowed for the code given below?
class A
public :int a;
class B:public A
int b;
main()
a) Casting 1
b) Casting 2
View Answer
Answer: b
Explanation: The casting 2 is correct. The objects casting must be done from derived
class object to a parent class object. That is, the object of the superclass can be made an
object of subclass only. Vice versa is not possible.
View Answer
Answer: c
Explanation: The upcasting of derived class object is possible to any base class. This is
because the base class object can represent any of its derived classes using upcasting.
View Answer
Answer: c
Explanation: 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.
d) Not allowed
View Answer
Answer: a
Explanation: The public inheritance shows the most flexible is-a relationship. Hence
explicit type casting is not required. Implicit type casting is done by the compiler.
a) Static binding
b) Dynamic binding
View Answer
Answer: b
Explanation: Since the implicit type casting allows casting of a base class pointer to refer
to its derived class object or even base class object. We need dynamic type casting so
that the references can be resolved during execution of program.
12. When are the pointer types known for upcasting the objects?
a) Compile time
b) Runtime
View Answer
Answer: a
Explanation: The pointer or reference types are known at compile time for the upcasting
of an object. This is because the addresses must be known for casting the derived class
to base class object.
13. When are the object type known for upcasting the objects?
a) Compile time
b) Runtime
View Answer
Answer: b
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.
14. 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();
View Answer
Answer: c
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.
View Answer
Answer: d
Explanation: The type of inheritance doesn’t matter with the upcasting concept. Upcasting
applies to all types of inheritance. Any derived class object can be upcasted to any of its
base class object.
1. What is downcasting?
View Answer
Answer: b
Explanation: The downcasting concept includes only the casting of supertypes to the sub
types. This casting is generally done explicitly. Larger size types are made to fit into small
size types explicitly.
View Answer
Answer: c
Explanation: The downcasting of any object must be done explicitly. This is because the
compilers don’t support the implicit conversion of a supertype to subtype.
3. Downcasting is _______________________
a) Always safe
b) Never safe
c) Safe sometimes
Answer: b
Explanation: The downcasting concept is made for exception cases. When there is a
need to represent an entity in the form which is not suitable for it. Representing a base
type in derived type is not right but can be done for special cases.
advertisement
4. Downcasting ____________________
View Answer
Answer: a
a) Static cast
b) Dynamic cast
c) Manual cast
d) Implicit cast
View Answer
Answer: b
Explanation: The dynamic cast can be done using the operator dynamic_cast. This
converts one type to another type in a safe way.
View Answer
Answer: a
a) void
b) null
c) void pointer
d) null pointer
View Answer
Answer: d
Explanation: The null pointer is returned by the dynamic_cast, if it fails. The conversion
sometimes fails because of too complex type conversion. The conversion may also fail
due to memory or some related issues.
a) dynamic_cast(object)
c) dynamic_cast(object)
d) dynamic_cast(object)
View Answer
Answer: c
Explanation: The dynamic_cast is the name of the operator, which is followed by the new
type in which the object have to be converted. Then the object name is given. This object
name is then used after the type conversion.
a) CastException
b) ClassCastingExeption
c) ClassCasting
d) ClassCastException
View Answer
Answer: d
Explanation: The exception handler for the exceptions produced during the downcasting
exception. This handler can be called during runtime to handle any exception thrown.
10. How to prevent the ClassCastExceptions?
a) By using instanceof
View Answer
Answer: a
Explanation: The instanceof operator can be used to check the compatibility of the
conversion. This has to be done to check whether the casting would be safe or not.
a) True
b) False
View Answer
Answer: b
Explanation: The downcasting is not possible in java directly. This has to be done
explicitly. The downcasting is not safe but can be checked for safe casting using
instanceof function.
View Answer
Answer: b
Explanation: The downcasting is always downward the inheritance order. Since the base
class object have to be casted into derived class type. This is a basic definition of
downcasting.
13. What happens when downcasting is done but not explicitly defined in syntax?
b) Runtime error
d) Conversion error
View Answer
Answer: a
Explanation: The implicit downcasting is not possible. If tried, the compiler produces an
error. Since the compiler doesn’t allow coasting to a type that is not compatible.
View Answer
Answer: c
Explanation: The downcasting can be used whenever there is a need to compare one
object to another. Equals() function can be used to compare whether the objects were of
same age. We can use getClass() function too.
View Answer
Answer: b
Explanation: The downcasting is possible because the classes in inheritance follow is-a
relationship. Hence the derived class is a base class. Which in turn make the
downcasting possible.
View Answer
Answer: b
Explanation: The new keyword is used to allocate memory of an object or array. The new
object or array can be of any type. Then it returns a suitable non zero pointer to the
object.
a) Modify a vtable
View Answer
Answer: c
Explanation: The new keyword is used for adding new vtable slot entries. This is an
additional feature in Microsoft C++. It can use predefined class object for this work.
View Answer
Answer: c
Explanation: While creating new objects, the new operator may fail because of memory
errors or due to permissions. At that moment the new operator returns zero or it may
throw an exception. The exception can be handled as usual.
advertisement
4. If new throws an error, which function can be called to write a custom exception handler?
a) _set_handler
b) _new_handler
c) _handler_setter
d) _set_new_handler
View Answer
Answer: d
d) Depends on code
View Answer
Answer: b
Explanation: The constructor function is called after the allocation of memory. In C++ the
feature works in a bit different way. The memory for all the data members is allocated first
and then the constructor function is called to finalize the memory allocated.
6. Which among the following is correct syntax to declare a 2D array using new operator?
View Answer
Answer: a
Explanation: The new operator usage to declare a 2D array requires a pointer and size of
array to be declared. Data type and then the pointer with size of array. The left index can
be left blank or any variable can be assigned to it.
View Answer
Answer: d
Explanation: The declaration of any data where we use new operator, any of the
mentioned types are not allowed. This is because the new operator allocated memory
based on the type of data which can be allocated dynamically.
View Answer
Answer: b
Explanation: The new operator doesn’t allocate reference types. This is because the
reference types are not objects. The new operator is used to allocate memory to the
direct objects.
a) New operator can’t allocate functions but pointer to functions can be allocated
View Answer
Answer: a
Explanation: The new operator can’t allocate functions but can allocate pointer to the
functions. This is a security feature as well as to reduce the ambiguity in code. The new
keyword is not given functionality to directly allocate any function.
a) Finalize
b) Arg
c) Initializer
d) Allocator
View Answer
Answer: c
Explanation: The new operator grammar is added with an initializer field. This can be
used to initialize an object with a user defined constructor. Hence can allocate memory as
intended by the programmer.
View Answer
Answer: c
Explanation: The initializers can’t be specified for arrays. The initializers can create arrays
of object if and only if the class has a default constructor. That is a zero argument
constructor so that it can be called without any argument.
View Answer
Answer: b
Explanation: It is not necessary that the objects get destroyed when they go out of scope
if allocated by using new operator. This is because new operator returns a pointer to
object that it had allocated. A suitable pointer with proper scope should be defined by the
programmer explicitly.
View Answer
Answer: a
Explanation: The new operator invokes function operator new. This is done to allocate the
storage to an object. ::operator new is called for storage allocation implicitly.
14. If a new operator is defined for a class and still global new operator have to be used,
which operator should be used with the keyword new?
a) Colon
b) Arrow
c) Dot
d) Scope resolution
View Answer
Answer: d
Explanation: As usual, scope resolution operator is used to get the scope of parent or the
global entities. Hence we can use scope resolution operator with the new operator to call
the global new operator even if new operator is defined for the class explicitly.
View Answer
Answer: a
Explanation: The compiler implicitly converts the syntax so that the instruction can be
understood by the processor and proper machine code can be generated. The
conversion is done implicitly and no explicit syntax is required.
View Answer
Answer: a
Explanation: The delete operator is the reverse process of a new operator. It deallocates
all the memory allocated for an object. The object can be of any type. The delete operator
completely destroys an object so that the resources can be used for other purposes.
2. If an object is allocated using new operator ____________
View Answer
Answer: a
Explanation: The new operator allocates an object in memory and hence the memory
allocation is bit different from usual allocation of an object. The delete operator can be
used to delete the memory allocated for an object.
d) No
View Answer
Answer: d
Explanation: The delete operator doesn’t return any value. Its function is to delete the
memory allocated for an object. This is done in reverse way as that new operator works.
advertisement
b) void pointer
c) null pointer
d) null
View Answer
Answer: a
Explanation: The result of the delete operator is void. The values returned is of no use to
the program or any other system function hence the return type is not defined for the
delete operator.
5. If delete is used to delete an object which was not allocated using new
_______________
View Answer
Answer: c
Explanation: When the delete operator is used with the objects that were not allocated
using new operator then unpredictable errors may arise. This is because the delete can’t
perform the required actions on the type of memory allocated for the object.
View Answer
Answer: c
Explanation: The delete operator can be used on pointers with the value 0. This actually
means that when new operator fails and return value 0 then deleting the result of failed
new remains harmless. Hence the deletion is possible.
View Answer
Answer: b
Explanation: The destructor is called before the memory is deallocated for any object.
The destructor call initiates the destruction process and the deallocation of memory takes
place.
View Answer
Answer: d
Explanation: After performing delete operation on an object whole l-value is modifiable, its
values becomes undefined. This is done so as to denote that the memory space is
available to be used for other purposes.
a) Only 1
b) Only 2
c) Only 3
d) Only 4
View Answer
Answer: b
Explanation: There are two variants of delete operator. One is for object deletion. Other is
for deletion of object array.
a) delete *objectName;
b) objectName delete;
c) delete objectName;
d) objectName *delete;
View Answer
Answer: c
Explanation: The object to be deleted is mentioned after the keyword delete. This deletes
the object from memory and free up the memory that was acquired by the object.
a) delete [] objectName;
b) delete * objectName;
c) objectName[] delete;
d) delete objectName[];
View Answer
Answer: a
Explanation: The object array that has to be deleted is mentioned after the keyword
delete. But after delete, empty square brackets have to be given to denote that the
deletion have to be done on array of objects.
12. Which cases among the following produces the undefined result?
View Answer
Answer: c
Explanation: The undefined result is always produced when we try to use delete [] with a
single object. Because the type of deletion mismatches. Same in case where we try to
apply delete to an object array.
View Answer
Answer: a
Explanation: The delete operator invokes the function operator delete. This function in
turn performs all the delete operations on the mentioned object. This is ensures safe
deletion.
View Answer
Answer: a
Explanation: The global delete operator is called to delete the objects that are not of class
type. Class type includes class, union or struct. All objects of these types can be deleted
using the global delete operator.
15. The delete operator __________________________
View Answer
Answer: a
Explanation: The delete operator can be defined for each class explicitly. If there is a
class for which delete is not defined then the global delete operator is used. The definition
of delete operator for each class is not necessary.
a) Global variables
b) Implicit/temporary variables
c) Local variables
d) System variables
View Answer
Answer: c
Explanation: The local variables are also known as automatic variables. The variables in
any local scope that are created and destroyed as the program executes its scope.
View Answer
Answer: b
Explanation: The memory is allocated and deallocated automatically for the automatic
variables. As soon as the variable comes in scope, the memory is allocated. The
variables are destroyed as soon as those go out of scope.
View Answer
Answer: d
Explanation: The automatic variables scope is limited only within the block or the function
where those are defined. This is the property of all the automatic variables.
advertisement
View Answer
Answer: a
Explanation: The automatic variables are hidden from the called function. Even if passed
by reference or address, the address of the variable is used and not the actual variable of
calling function. Automatic variables can be const or variable.
View Answer
Answer: b
Explanation: The automatic variables are saved till the called function gets executed. This
is done so as to ensure that the program can continue its execution after the called
function is returned. The automatic variables gets destroyed only if those go out of scope.
6. Where are the automatic variables stored if another function is called in between the
execution of the program?
a) Heap
b) Queue
c) Stack
d) Temp variable
View Answer
Answer: c
Explanation: All the automatic variables are stored in a new stack entry as soon as their
scope is created. If another function is called, the present data is saved in stack and new
entry in stack is made for the called function. When the function returns, the automatic
variables are used again from where those were left.
View Answer
Answer: b
Explanation: The static members can’t be automatic. This is because the automatic
variables are created and destroyed with each call to a specific function. But the static
members remain throughout the execution of program once created.
Answer: d
Explanation: The variables declared inside a block, are make automatic by default. This is
to ensure that the variables get destroyed when not required. The variables remain live
only till those are required, the life is dependent on the scope of a variable.
a) Null value
b) Void value
c) Undefined/Garbage
d) Zero value
View Answer
Answer: c
Explanation: The automatic variable which are not initialized, contain garbage value. If we
just declare a variable and try to print its value, the result is some unknown value. The
value is garbage as that was not expected value.
View Answer
Answer: a
Explanation: Only when the execution reaches the place where the automatic variable
was declared, the constructor is called. This is to ensure that the memory is not allocated
if not needed. The memory is allocated and then destroyed as soon as it goes out of
scope.
View Answer
Answer: d
Explanation: The auto and register keywords are not supported in java. Though the same
is allowed in java without specifying any of those keywords. The variables are local
variables. But java makes it mandatory to initialize all of the local variables in a program.
View Answer
Answer: b
Explanation: All the automatic variables in a program must be declared before their use.
The compiler won’t allow any use of variable if those are not declared before their use.
13. Which error is produced if the automatic variables are used without declaration?
a) Undefined symbol
b) Memory error
c) Type mismatch
d) Statement missing
View Answer
Answer: a
Explanation: If the automatic variables are used without declaration or are used before
the declaration then the compiler throws an error. The error that the symbol is undefined.
The compiler must know everything before that can be used.
14. In Perl, using which operator are the local variables created?
a) Dot
b) Arrow
c) Scope resolution
d) my
View Answer
Answer: d
Explanation: The language perl supports local variables but the concept is bit different.
And if the values are not assigned to the local variables then it contains undef value.
15. How are automatic variables different from the instance variables?
View Answer
Answer: d
View Answer
Answer: b
Explanation: The variables that are declared in another source file can be accessed in
other files using extern variables. The extern variables must be mentioned explicitly. The
source file is included to use its variables.
View Answer
Answer: a
Explanation: The variables can be declared any number of times. There is no restriction
on how many times a single variables can be declared. Declaration is just an indication
that the variable will be used in the program.
View Answer
Answer: a
Explanation: The variables can be defined only once. Once the variable is defined, then it
can’t be declared again. The definition of a variable is actual allocation of memory for the
variable.
advertisement
a) The source file must not be included in the new file code
Answer: c
Explanation: The source file must be included in the file which needs to use the extern
variable. This is done to ensure that the variables that are already declared can be used
again. Only the declarations are used from one file to another.
View Answer
Answer: a
Explanation: The header file only contains the declaration of variables that are extern. It
doesn’t contain any static variable definitions.
View Answer
Answer: d
Explanation: Only one header file should declare the extern variable to be used. There
must not be more than one file declaring the same extern variable. This is to ensure that
there is no ambiguity in using the extern variable.
View Answer
Answer: c
Explanation: Even if we don’t specify a function to be extern, by default all the functions
are exter. The compiler adds the keyword at the beginning of the function declaration. If
there is an extern function to be used then it will be used otherwise the new function only
will be used.
a) True
b) False
View Answer
Answerr: b
Explanation: The statement is false. The variables are not extern by default. If those are
made extern by default, then the memory will never be allocated for those extern
variables. Hence we make the variables extern explicitly.
9. Which of the following results in the allocation of memory for the extern variables?
a) Declaration
b) Definition
c) Including file
View Answer
Answer: b
Explanation: The memory for the extern variables are allocated due to their definition.
When the variables are declared, it only indicates the compiler that the variable is going
to be used somewhere. But definition makes the compiler to allocate the memory for the
variables.
b) extern variable_name;
d) extern (data_type)variable_name;
View Answer
Answer: a
Explanation: The syntax firstly contains the keyword extern. Then the data type of the
variable is given. Then the variabel name is mentioned by which it will be used in the
program.
a) extern function_name(argument_list);
b) extern return_type function_name(argument_list);
c) extern (return_type)function_name(argument_list);
View Answer
Answer: b
Explanation: The syntax must contain the keyword extern first, to denote that the function
is extern. Though the function are extern by default but among the given choices, it
should contain the keyword, for explicit declaration. Then the usual function declaration
follows.
int main(void)
var = 10;
var++;
cout<<var;
a) 10
b) 11
Answer: d
Explanation: The program gives the compiler time error. There is no definition given for
the extern variables. This is not allowed and hence we get a compile time error.
13. If the definition is given in the header file that we include then ________________
View Answer
Answer: a
Explanation: The program runs successfully. This is because only one definition of any
variable is allowed. And hence the definition from the source file that is included will be
used.
View Answer
Answer: c
Explanation: When the value for the extern variable is defined with its declaration, then
there is no need to include any file for the definition of the variable. The Initialization acts
as a definition for the extern variable in the file itself.
View Answer
Answer: a
Explanation: The program have all of its functions visible throughout the program usually.
Also, there is no specific value that a function must contain. Hence the functions are
extern by default.
View Answer
Answer: a
Explanation: The classes that are already provided in a programming language for use
are inbuilt classes. These classes provide some functions or objects that can be used by
the programmer for easier code.
2. Inbuilt class __________________________
View Answer
Answer: a
Explanation: The inbuilt classes must be included in the program. Whenever some
functions are used, they must have a declaration before use. The same is the case with
classes.
a) Function prototype
b) Function declaration
c) Function definitions
d) Objects
View Answer
Answer: c
Explanation: The classes contain the definitions of the special functions that are provided
for the programmers use. Those functions can be used to make the programming easy
and to reuse the already existing code.
advertisement
b) Color
c) String
d) Functions
View Answer
Answer: d
Explanation: There is no inbuilt class named function in java. The others are classes
already provided in java. All those classes contain some special functions to be used in
programming.
View Answer
Answer: a
Explanation: The InputStream is an inbuilt class which is used to handle all the tasks
related to input handling. This class extends input from keyboard or file or any other
possible input stream.
View Answer
Answer: c
Explanation: The Array class is associated with all the other classes. This gives us the
flexibility to declare an array of any type. The index goes from 0 to n, where n is some
fixed size for array.
View Answer
Answer: b
Explanation: The Math class is provided with some special functions. These functions can
be used to calculate and get result of some special and usual mathematical functions. We
don’t have to write the code to calculate the trigonometric function results, instead we can
use Math functions.
a) StreamingInput
b) StreamedInput
c) StreameInput
d) StreamInput
View Answer
Answer: d
Explanation: The DataInputStream is more specific class for operating on specific type of
data inputs. This is used to read data of specific type. The same can be used to read data
in a specific format.
a) Size.Array
b) Array.Size
c) Array_name.length
d) length.Array_name
View Answer
Answer: c
Explanation: The array name is given of which the length have to be calculated. The
array length is stored in the attribute length. Hence we access it using dot operator.
a) Integer values
b) Float values
c) Byte values
d) Character values
View Answer
Answer: d
Explanation: The Number class is used to work with all the number type of values. The
integers, float, double, byte etc. are all number type values. Character is not a number
value.
11. Which function should be used to exit from the program that is provided by System
class?
a) exit(int);
b) gc();
c) terminate();
d) halt();
View Answer
Answer: a
Explanation: The exit function should be used to terminate the program. The function is
passed with an argument. The argument indicated the type of error occurred.
a) Finalize
b) System
c) Final
d) SystemFinal
View Answer
Answer: b
Explanation: The runFinalization() Function is defined in the System class. The function is
used to finalize an object which undergo destruction. The action is required to terminate
the object properly.
View Answer
Answer: a
Explanation: Only the specified path named dynamic libraries are loaded. All the dynamic
libraries can’t be loaded at a time. Hence we use this function for specific libraries.
a) err
b) out
c) in
d) put
View Answer
Answer: d
Explanation: Put is not a System class variable. The most general and basic variables are
err, out and in. The variables can handle most of the tasks performed in a program.
15. Which package contains the utility classes?
a) java.lang
b) java.utility
c) java.util
d) java.io
View Answer
Answer: c
Explanation: The package java.util contains all the utility classes. This package also
contains generic data structures, date, time etc. These can be used in any java program,
you just have to include java.util package.
View Answer
Answer: c
Explanation: The IO class provides functions that can be used to handle input and output
operations. All the inputs from standard input and standard output, and also from the files
can be handled. This gives the flexibility to make the programs more user friendly.
a) Data streams
b) Serialization
c) File system
View Answer
Answer: d
Explanation: The IO classes are made such that those can support the input and output
from any type of source or destination. The input can be taken from system file and
standard input and also some special devices if conned. Same is case to show the
output.
3. Which among the following class contains the methods to access character based
console device?
a) Console
b) File
c) Device
d) Pipe
View Answer
Answer: a
Explanation: The Console class contains the methods to access the character based
devices. The devices which can stream the data as character set. All those devices can
be made use of by using the methods of class Console.
advertisement
View Answer
Answer: c
Explanation: The File class is made to operate with the files. The file can be of any type.
All the input and output operations that have to be performed on a file can be done using
File class object.
5. What is a FileDescriptor?
View Answer
Answer: a
Explanation: The machine specific structure of an open file have to be handled in some
special ways. FileDescriptor class can handle those files. The FileDescriptor can also
handle open socket, another source, sink of bytes.
6. FileInputStream _________________________
View Answer
Answer: d
Explanation: The most specific answer is that the FileInputStream can only be used for
the opened files. The class can work only for the file type. No socket or another source
are allowed to be accessed.
View Answer
Answer: d
Explanation: The FilePermission can’t get access to the device access permissions. The
Permission is given to a file when it is created or otherwise when a privileged user
changes it. Then these permission rights can be accessed using the FilePermission
class.
a) LineNumberInputStream
b) LineNumberReader
c) LineReader
d) LineBuffer
View Answer
Answer: a
View Answer
Answer: b
Explanation: The Reader class is an abstract class that can be used to read characters
stream. It can’t be used for any kind of input. It can just read the existing data.
a) ExceptionIO
b) InteruptedIO
c) InteruptedIOException
d) IOInteruptException
View Answer
Answer: c
Explanation: The only class which handles the IO class interrupts is
InteruptedIOException class. This class is specially provided to handle any case that
involves the execution interrupt.
View Answer
Answer: d
Explanation: The StringReader can only work with the string type data. Even if a
character array is given, it might produce some errors in code. Hence only the string
values can be handled properly.
12. Which exception handler can be used when character encoding is not supported?
a) UnsupportedException
b) UnsupportedEncodingException
c) SupportException
d) EncodingException
View Answer
Answer: b
a) True
b) False
View Answer
Answer: a
Explanation: The PushBackReader allows the character streams handling. The main
feature is that the stream can be pushed back to the stream. This is used in special cases
of handling input stream.
View Answer
Answer: c
Explanation: The RandomAccessFile class instance can be created to handle input and
output operations to a random access file. It first checks the permissions on the file and
then any required operation can be done on a random access file. Comparatively faster
than other files access.
15. Which among the following is a serialization descriptor for any class?
a) StreamClass
b) ObjectStreamClass
c) ObjectStream
d) StreamObjectClass
View Answer
Answer: b
View Answer
Answer: a
Explanation: The object of string class are mostly immutable. This means that the String
objects are constant. These can’t be changed once created.
Answer: a
Explanation: The class name String is given. And then the object name is mentioned.
There are two ways to declare and initialize the string. Either by giving direct string value
or by using new keyword. But if new operator is used, constructor of String class have to
be called. From the given options, the direct string value declaration is correct.
View Answer
Answer: b
Explanation: The length function returns the length of string. The length is the number of
characters in the string but the last null character is not counted. The string length can be
used to loop through each character in the string.
advertisement
4. Which is the function to get the character present at a particular index in the string?
a) char charAt(index);
b) char charIn(StringName);
c) char charAt(StringName);
d) char charIn(index);
View Answer
Answer: a
Explanation: The function can be called using dot operator with the string object. Char is
the return type of the function to return the character at specified position. The index must
be an integer value, less than the length of string.
d) It returns the string from starting of string till the specified index
View Answer
Answer: c
Explanation: The substring function returns a string value. The string is the substring
starting from the specified index till the end. The substring function have to be called with
the object of string class.
b) String starting from first index and of length equal to send argument
c) String starting from first index and of length equal to sum of two arguments
d) String starting from first index and ending at second index position
View Answer
Answer: d
Explanation: A value of string type is returned from this function. The returned string is a
substring that starts from the first argument position, till the second index position. The
indices must be less than the length of actual string.
View Answer
Answer: c
Explanation: The concat function is used to append string into another string. The new
string is always appended at the end of source string. The target string is appended as it
is and the whole string is then ended by null character.
View Answer
Answer: a
Explanation: The function is used to get the last occurrence index of a character present
in a string. The return type is char. Single character is returned. The function is used with
a string object and the target character is passed as its argument.
9. Function equals() is _______________ and equalIgnoreCase() is _________________
View Answer
Answer: b
Explanation: Both the functions return Boolean value. The function equal() is case
sensitive and returns false even if a single character is case different in two strings. The
other function ignores the case sensitivity and only checks if the spellings are same.
View Answer
Answer: c
Explanation: The source and target must be objects of the string class. The compare is
always case sensitive. To compare two string objects without case sensitivity then we can
use compareToIgnoreCase() function.
View Answer
Answer: c
Explanation: The function is used to convert each character of the string. If the character
is already uppercase then it remains the same. But if some character is in lowercase then
it will be converted to uppercase.
View Answer
Answer: d
Explanation: The function is used to remove any white space from both the ends of a
given string. The white space include space, tab, next line etc. It will be removed both
from the starting of string and from the end of string.
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: b
Explanation: The first argument is the target character. This target character will be
replaced by another character. The new character is the second argument to the function.
Only the characters can be passed as argument, not a string.
14. If two arguments are passed to the indexOf() function then ___________________
a) Second argument indicates the occurrence number of specified character from starting
b) Second argument indicates the occurrence number of specified character from end
d) Second argument indicates the index of the character from the last of the string
View Answer
Answer: a
Explanation: The string may have more than one occurrence of a character. We use this
function to get the index at which the specified number of times a specific character has
occurred in a string. For example, we can get the index of 5th occurrence of character “j”
in a string.
15. The string class deals with string of only character type.
a) True
b) False
View Answer
Answer: a
Explanation: The string class objects can be used for any string consisting of characters.
The characters include numbers, alphabets and few special characters. String class is
not necessary to be used but provides a huge set of inbuilt functions to make the string
operations easier.