You are on page 1of 114

1.

Passing object to a function _______________

a) Can be done only in one way

b) Can be done in more than one ways

c) Is not possible

d) Is not possible in OOP

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.

2. The object ________________

a) Can be passed by reference

b) Can be passed by value

c) Can be passed by reference or value

d) Can be passed with reference

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.

3. Which symbol should be used to pass the object by reference in C++?

a) &
b) @

c) $

d) $ or &

View Answer

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.

advertisement

4. If object is passed by value ______________

a) Copy constructor is used to copy the values into another object in the function

b) Copy constructor is used to copy the values into temporary object

c) Reference to the object is used to access the values of the object

d) Reference to the object is used to created new object in its place

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.

5. Pass by reference of an object to a function _______________

a) Affects the object in called function only

b) Affects the object in prototype only


c) Affects the object in caller function

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.

6. Copy constructor definition requires __________________

a) Object to be passed by value

b) Object not to be passed to it

c) Object to be passed by reference

d) Object to be passed with each data member value

View Answer

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.

7. What is the type of object that should be specified in the argument list?

a) Function name

b) Object name itself

c) Caller function name

d) Class name of object


View Answer

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.

8. If an object is passed by value, _________________

a) Temporary object is used in the function

b) Local object in the function is used

c) Only the data member values are used

d) The values are accessible from the original object

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.

9. Can data members be passed to a function using the object?

a) Yes, it can be passed only inside class functions

b) Yes, only if the data members are public and are being passed to a function outside the
class

c) No, can’t be passed outside the class

d) No, can’t be done

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.

10. What exactly is passed when an object is passed by reference?

a) The original object name

b) The original object class name

c) The exact address of the object in memory

d) The exact address of data members

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?

a) The data members should be passed separately

b) The data members and member functions have to be passed separately

c) The values should be present in other variables

d) The object must be passed

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.

12. Which among the following is true?

a) More than one object can’t be passed to a function

b) Any number of objects can be passed to a function

c) Objects can’t be passed, only data member values can be passed

d) Objects should be passed only if those are public in class

View Answer

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.

13. What will be the output if all necessary code is included (Header files and main
function)?

void test (Object &y)


{
y = "It is a string";
}
void main()
{
Object x = null;
test (x);
System.out.println (x);
}

a) Run time error


b) Compile time error

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.

14. In which type is new memory location will be allocated?

a) Only in pass by reference

b) Only in pass by value

c) Both in pass by reference and value

d) Depends on the code

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?

a) Can only be returned by value

b) Can only be returned by reference

c) Can be returned either by value or reference

d) Can neither be returned by value nor by reference

View Answer

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.

2. Whenever an object is returned by value ____________________

a) A temporary object is created

b) Temporary object is not created

c) Temporary object may or may not be created

d) New permanent object is created

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?

a) Outside the function scope

b) Within the function

c) Inside the main function

d) Inside the calling function

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

4. Which is the correct syntax for returning an object by value?

a) void functionName ( ){ }

b) object functionName( ) { }

c) class 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.

6. If an object is declared inside the function then ____________________ outside the


function.

a) It can be returned by reference

b) It can’t be returned by reference

c) It can be returned by address

d) It can’t be returned at all

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?

a) Out of memory error

b) Run time error

c) Compile time error

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 ____________________

a) Temporary object is created

b) Temporary object is created inside the function

c) Temporary object is created for few seconds

d) Temporary object is not created

View Answer

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.

10. Which among the following is correct?

a) Individual data members can’t be returned

b) Individual data members can be returned

c) Individual member functions can be returned from another function

d) Individual data members can only be passed by reference

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.

11. Can we return an array of objects?

a) Yes, always
b) Ye, only if objects are having same values

c) No, because objects contain many other values

d) No, because objects are single entity

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.

12. If an object is passed by reference to a function then it must be returned by reference.

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.

13. Which among the following is true?

a) Two objects can point to the same memory location

b) Two objects can never point to the same memory location

c) Objects not allowed to point at a location already occupied

d) Objects can’t point to any address


View Answer

Answer: a

Explanation: When an object is created and instead of calling a constructor, another


object is assigned to it. Both the objects point to the same memory location. This can be
illustrated with help of return by reference.

14. If an object is being returned by value then __________________________

a) Its member values are made constant

b) Its member values have to be copied individually

c) Its member values are not used

d) Its member values are copied using copy constructor

View Answer

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.

15. Why temporary object is not created in return by reference?

a) Because compiler can’t create temporary objects

b) Because the temporary object is created within the function

c) Because return by reference just make the objects points to values memory location

d) Because return by reference just make the object point to null

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.

1. When value of an object is assigned to another object ________________

a) It becomes invalid statement

b) Its values gets copied into another object

c) Its values gets address of the existing values

d) The compiler doesn’t execute that statement

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.

2. If an object is created and another object is assigned to it, then ________________

a) Copy constructor is called to copy the values

b) Object is copied directly to the object

c) Reference to another object is created

d) The new object is initialized to null 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?

a) Assigned using copy constructor at time of passing

b) Copied directly

c) Uses addresses always

d) Doesn’t get initialized

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

4. Predict the output of the program.

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.

5. If programmer doesn’t define any copy assignment operator then


____________________

a) Compiler gives an error

b) Program fails at run time

c) Compiler gives an implicit definition


d) Compiler can’t copy the member values

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.

6. Declaring a copy constructor doesn’t suppresses the compiler generated 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 ________

a) Only const objects will be accepted

b) Only non – const objects are accepted

c) Only const members will not get copied

d) Compiler generates an error

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.

8. How many objects can be assigned to a single address?

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.

9. Use of assignment operator ____________________

a) Changes its use, when used at declaration and in normal assignment

b) Doesn’t changes its use, whatever the syntax might be

c) Assignment takes place in declaration and assignment syntax

d) Doesn’t work in normal syntax, but only with declaration

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 __________

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

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

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.

12. We can assign ______________________

a) Value of one reference variable to another


b) Value of any object to another

c) Value of any type to any object

d) Value of non – reference to another reference

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.

13. Assigning reference to an object _________________

a) Will create another copy of the object

b) Will create two different copies of the object

c) Will not create any other copy of the object

d) Will not refer to the object

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.

14. Which among the following is true?

a) We can use direct assignment for any object

b) We can use direct assignment only for different class objects

c) We must not use direct assignment


d) We can use direct assignment to same class objects

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.

15. Assigning objects takes place while passing the arguments.

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.

1. Which language among the following doesn’t allow pointers?

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.

2. Which is correct syntax for declaring pointer to object?

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

b) Colon to the member

c) Scope resolution 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?

a) Using object name

b) Using an integer pointer

c) Using this pointer

d) Using void pointer

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.

5. If pointer to an object is declared __________

a) It can store any type of address

b) It can store only void addresses

c) It can only store address of integer type

d) It can only store object address of class type specified

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?

a) Equal to size of any usual pointer

b) Equal to size of sum of all the members of object

c) Equal to size of maximum sized member of object

d) Equal to size of void

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 _________________

a) Can point to only one object at a time

b) Can point to more than one objects at a time

c) Can point to only 2 objects at a time

d) Can point to whole class objects at a time

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
_________

a) derived-to-base implicit conversion for pointers


b) base-to-derived implicit conversion for pointers

c) base-to-base implicit conversion for pointers

d) derived-to-derived implicit conversion for pointers

View Answer

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.

9. Can pointers to object access the private members of the class?

a) Yes, always

b) Yes, only if it is only pointer to object

c) No, because objects can be referenced from another objects too

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.

10. Is name of an array of objects is also a pointer to object?

a) Yes, always

b) Yes, in few cases


c) No, because it represents more than one object

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.

11. Which among the following is true?

a) The pointer to object can hold address only

b) The pointer can hold value of any type

c) The pointer can hold only void reference

d) The pointer can’t hold any value

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 __________

a) It becomes void pointer

b) It becomes dangling pointer

c) It becomes null pointer

d) It becomes zero pointer

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.

14. How can the address stored in the pointer be retrieved?

a) Using * symbol

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.

15. What should be done to prevent changes that may be made to the values pointed by the
pointer?

a) Usual pointer can’t change the values pointed

b) Pointer should be made virtual

c) Pointer should be made anonymous

d) Pointer should be made const

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.

16. References to object are same as pointers of object.

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.

2. Which among the following is true?

a) this pointer is passed implicitly when member functions 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.
3. The this pointer is accessible __________________

a) Within all the member functions of the class

b) Only within functions returning void

c) Only within non-static functions

d) Within the member functions with zero arguments

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

4. An object’s this pointer _____________________

a) Isn’t part of class

b) Isn’t part of program

c) Isn’t part of compiler

d) Isn’t part of object itself

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.

5. The result of sizeof() function __________________


a) Includes space reserved for this pointer

b) Includes space taken up by the address pointer by this pointer

c) Doesn’t include the space taken by this pointer

d) Doesn’t include space for any data member

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.

6. Whenever non-static member functions are called _______________

a) Address of the object is passed implicitly as an argument

b) Address of the object is passed explicitly as an argument

c) Address is specified globally so that the address is not used again

d) Address is specified as return type of the function

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,&parameter)

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.

8. The address of the object _________________

a) Can’t be accessed from inside the function

b) Can’t be accessed in the program

c) Is available inside the member function using this pointer

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.

9. Which among the following is true?

a) This pointer can be used to guard against any kind of reference

b) This pointer can be used to guard against self-reference

c) This pointer can be used to guard from other pointers


d) This pointer can be used to guard from parameter referencing

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.

10. Which syntax doesn’t execute/is false when executed?

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.

11. The this pointers _____________________

a) Are modifiable

b) Can be assigned any value

c) Are made variables

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.

12. Earlier implementations of C++ ___________________

a) Never allowed assignment to this pointer

b) Allowed no assignment to this pointer

c) Allowed assignments to this pointer

d) Never allowed assignment to any pointer

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.

13. This pointer can be used directly to ___________

a) To manipulate self-referential data structures

b) To manipulate any reference to pointers to member functions

c) To manipulate class references

d) To manipulate and disable any use of pointers

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.

14. Which among the following is/are type(s) of this pointer?

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?

a) classType [cv-qualifier-list] *const this;

b) classType const[cv-qualifier-list] *this;

c) [cv-qualifier-list]*const classType this;

d) [cv-qualifier-list] classType *const this;

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.

1. What are default arguments?

a) Arguments which are not mandatory to be passed

b) Arguments with default value that aren’t mandatory to be passed

c) Arguments which are not passed to functions

d) Arguments which always take same data 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.

2. Which is the correct condition for the default arguments?

a) Those must be declared as last arguments in argument list

b) Those must be declared first in the argument list

c) Those can be defined anywhere in the argument list

d) Those are declared inside the function definition

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?

a) Two normal and one default argument

b) At least one default argument

c) Exactly one default argument

d) Make all the arguments default

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

4. Which among the following function can be called without arguments?

a) void add(int x, int y=0)

b) void add(int=0)

c) void add(int x=0, int y=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 ______________

a) The function will use the values passed to it

b) The function will use the default values as those are local

c) The function can use any value whichever is higher

d) The function will choose the minimum values

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.

6. Which among the following is correct?

a) void test(int x=0, int y, int z=0)

b) void test(int x=0, int=0)

c) void test(int x, int y=0)

d) void test(int x=’c, int y)

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.

7. What function will be called with the independent syntax “test(5,6,7);”?


a) void test(int x, int y)

b) void test(int x=0, int y, int z)

c) int test(int x=0, y=0, z=0)

d) void test(int x, int y, int z=0)

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

9. 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 values

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.

10. 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 declaration

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 ____________________

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 program

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.

12. 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 arguments

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.

a) Checked for availability

b) Checked for random access

c) Checked for accessibility


d) Checked for feasibility

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.

14. 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 call

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.

15. 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 classes

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.

1. 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 types

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.

2. 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 constructor

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

4. 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 class

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.

5. 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)

View Answer

Answer: b

Explanation: For a parameterized constructor to be used as a default constructor, it must


have all the default arguments. This makes the constructor to have optional arguments
which are not mandatory to be passed.

6. 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, 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?

a) default constructorName(default int x=0)


b) constructorName(default int x=0)

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?

Prototype: className(int x, int y, int z=0);

a) 1

b) 2

c) 3

d) Compile time error

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

c) The constructors might have same number of arguments

d) The constructors can’t be overloaded with respect to default arguments

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.

10. 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 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’);?

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);

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.

12. 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);

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 _________________

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 error

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.

14. 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 arguments

View Answer

Answer: d

Explanation: 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.

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

b) One default value constructor

c) Defining the default constructor

d) Using one constructor with two arguments


View Answer

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?

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 type

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.

2. 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 inheritance

View Answer
Answer: b

Explanation: The upcasting concept in inheritance is always applied upward the


inheritance tree. The derived class objects can be type casted to any of its parent class
type. Since is a relationship applies in general inheritance.

3. 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 versa

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

4. 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 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.

5. Which property is shown most when upcasting is used?

a) Code reusability

b) Code efficiency

c) Complex code simple syntax

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()

B b=new A(); //casting 1

A a=new B(); //casting 2

a) Casting 1

b) Casting 2

c) casting 1 and casting 2

d) casting 1 nor 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.

8. 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 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.

9. 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 upcasted

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.

10. 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 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.

11. Which concept is needed because of implicit type casting use?

a) Static binding

b) Dynamic binding

c) Compile time binding

d) Source code 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

c) Source code build time

d) Doesn’t apply to pointer types

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

c) Source code build time

d) Doesn’t apply to objects directly

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.

15. 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 inheritance

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?

a) Casting subtype to supertype

b) Casting supertype to subtype


c) Casting subtype to supertype and vice versa

d) Casting anytype to any other type

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.

2. 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 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

d) Safe, depending on code


View Answer

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 ____________________

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 error

View Answer

Answer: a

Explanation: 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.

5. What should be used for safe downcast?

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.

6. 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 address

View Answer

Answer: a

Explanation: The address of the object which is converted is returned by the


dynamic_cast operator. This is done to safely convert the subtype to supertype. This
ensures the proper assignment and conversion from one type to another.

7. If dynamic_cast fails, which value is returned?

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.

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)

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.

9. Which is the exception handler for the exceptions of downcasting?

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

b) By using is-a check

c) By using arrow operator with check function

d) By checking type of conversion

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.

11. Java supports direct downcasting.

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.

12. 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 matter

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?

a) Compile time error

b) Runtime error

c) Code write time 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.

14. 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 inheritance

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.

15. 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 casting

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.

1. What is the new operator?

a) Allocates memory for an object or array

b) Allocates memory for an object or array and returns a particular pointer

c) Used as return type when an object is created

d) Used to declare any new thing in a program

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.

2. Microsoft C++ Components extensions support new keyword to _____________

a) Modify a vtable

b) Replace a vtable slot entry

c) Add new vtable slot entries

d) Rearrange vtable slot entries

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.

3. What happens when new fails?

a) Returns zero always

b) Throws an exception always

c) Either throws an exception or returns zero

d) Terminates the program

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

Explanation: If the default exception handler has to be replaced by a user defined


handler, we can call _set_new_handler run-time library function with the function name as
an argument. This lets the programmer to give a custom definition for handling new
operator failure.

5. In C++, if new operator is used, when is the constructor called?

a) Before the allocation of memory

b) After the allocation of memory

c) Constructor is called to allocate memory

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?

a) char (*pchar)[10] = new char[][10];

b) char (pchar) = new char[][10];

c) char (*char) = new char[10][];

d) char (*char)[][10]= new char;

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.

7. For declaring data by using new operator ____________________

a) Type name can’t contain const

b) Type name can’t contain volatile

c) Type name can’t contain class declarations

d) Type name can’t contain const, volatile, class declaration or enumerations

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.

8. The new operator _____________

a) Can allocate reference types too


b) Doesn’t allocate reference types

c) Can allocate reference to objects

d) Doesn’t allocate any data

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.

9. Which among the following is true?

a) New operator can’t allocate functions but pointer to functions can be allocated

b) New operator can allocate functions as well as pointer to functions

c) New operator can allocate any type of functions

d) New operator is not applicable with functions allocation

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.

10. Which among the following is added in grammar of new operator?

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.

11. Initializers __________________

a) Are used for specifying arrays

b) Are used to defined multidimensional arrays

c) Can’t be specified for arrays

d) Can’t be specified for any data

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.

12. The objects allocated using new operator ________________

a) Are destroyed when they go out of scope

b) Are not destroyed even if they go out of scope

c) Are destroyed anytime

d) Are not destroyed throughout the program execution

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.

13. The new operator _________________

a) Invokes function operator new

b) Doesn’t invoke function operator new

c) Invokes function operator only if required

d) Can’t invoke function operator new implicitly

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.

15. How does compiler convert “::operator new” implicitly?

a) ::operator new( sizeof( type ) )

b) ::operator new( sizeof( ) )

c) new operator :: type sizeof( type )

d) new sizeof( type ) operator

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.

1. What is a delete operator?

a) Deallocates a block of memory

b) Deallocates whole program memory

c) Deallocates only primitive data memory

d) Deallocates all the data reserved for a class

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 ____________

a) It should be deleted using delete operator

b) It can’t be deleted using delete operator

c) It may or may not be deleted using delete operator

d) The delete operator is not applicable

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.

3. Does delete return any value?

a) Yes, positive value

b) Yes, negative value

c) Yes, zero value

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

4. Which type of value has resulted from the delete operator?


a) void

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
_______________

a) Then out of memory error arises

b) Then unreachable code error arises

c) Then unpredictable errors may arise

d) Then undefined variable error arises

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.

6. Delete operator _________________

a) Can be used on pointers with null value


b) Can be used on pointers with void value

c) Can be used on pointer with value 0

d) Can be used on pointer with any value

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.

7. When delete operator is used ___________________ (If object has a destructor)

a) Object destructor is called after deallocation

b) Object destructor is called before deallocation

c) Object destructor is not used

d) Object destructor can be called anytime during destruction

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.

8. If delete is applied to an object whose l-value is modifiable, then _______________ after


the object is deleted.

a) Its value is defined as null

b) Its value is defined as void


c) Its value is defined as 0

d) Its value is undefined

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.

9. How many variants of delete operator are available?

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.

10. Which is the correct syntax to delete a single object?

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.

11. Which is the correct syntax to delete an array of objects?

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?

a) delete [] on an independent object

b) delete on an object array

c) delete [] on an object and delete on object array

d) Undefined result is never produced

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.

13. The delete operator __________________

a) Invokes function operator delete

b) Invokes function defined by user to delete

c) Invokes function defined in global scope to delete object

d) Doesn’t invoke any function

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.

14. For objects that are not of class type ______________

a) Global delete operator is invoked

b) Local delete operator is invoked

c) Global user defined function is invoked

d) Local function to delete object is called

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 __________________________

a) Can be defined for each class

b) Can’t be defined for each class

c) Can be defined globally only

d) Can’t be defined in a program explicitly

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.

1. What are automatic variables?

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.

2. The memory for automatic variables ___________________

a) Have to be allocated and deallocated explicitly


b) Are allocated and deallocated automatically

c) Is never actually allocated

d) Are never safe

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.

3. Scope of an automatic variable _______________

a) Is actually the whole program

b) Is actually never fixed

c) Is always equal to the whole program execution

d) Is actually function or block in which it is defined

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

4. Which among the following is true for automatic variables in general?

a) Automatic variables are invisible to called function

b) Automatic variables are always visible to the called function


c) Automatic variables can’t interact with the called function

d) Automatic variables can’t be variable

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.

5. If an automatic variable is created and then a function is called then ________________

a) The automatic variable created gets destroyed

b) The automatic variable doesn’t get destroyed

c) The automatic variable may or may not get destroyed

d) The automatic variable can’t be used in this case

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.

7. The static variables of a function ________________

a) Are also automatic variables

b) Are not automatic variables

c) Are made automatic by default

d) Can be made automatic explicitly

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.

8. All variables declared within a block ____________________

a) Are not always automatic

b) Can be made non-automatic

c) Are static by default

d) Are automatic by default


View Answer

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.

9. What values does uninitialized automatic variables contain?

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.

10. Constructor of automatic variables is called ____________________

a) When execution reaches the place of declaration of automatic variables

b) When the program is compiled

c) When the execution is just started

d) Just before the execution of the program

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.

11. Does java contain auto or register keywords?

a) Yes, for declaring every type of variable

b) Yes, only to declare cache registers

c) No, because java doesn’t support automatic variables

d) No, java supports local variable concept

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.

12. The automatic variables _________________________

a) Must be declared after its use

b) Must be declared before using

c) Must be declared, can be anytime

d) Must not be initialized

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?

a) Automatic variables are initialized automatically but instances are not


b) Automatic variables are given zero values initially and not instances

c) Instance variables have to be initialized explicitly and automatic implicitly

d) Instance variables are initialized implicitly while automatic are not

View Answer

Answer: d

Explanation: The automatic variables have to be initialized explicitly. But in case of


instances, those are initialized automatically during execution of the program. The
conventions are mandatory.

1. What is extern variable?

a) Variables to be used that are declared in another object file

b) Variables to be used that are declared in another source file

c) Variables to be used that are declared in another executable file

d) Variables to be used that are declared in another program

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.

2. Which among the following is a correct statement for variables?

a) Variable can be declared many times

b) Variable can be declared only one time

c) Variable declaration can’t be done more than ones


d) Variable declaration is always done more than one time

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.

3. Which among the following is true for the variables?

a) Variable can be defined only once

b) Variable can be defined any number of times

c) Variable must be defined more than one time

d) Variable can be defined in different files

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

4. To use extern variable _____________________

a) The source file must not be included in the new file code

b) The source file itself must be used for a new program

c) The source file must be included in the new file

d) The source file doesn’t matter for extern variables


View Answer

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.

5. What does a header file contain for an extern variable?

a) Only declaration of variables

b) Only definition of variables

c) Both declaration and definition of variables

d) Neither declaration nor definition

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.

6. Which condition is true if the extern variable is used in a file?

a) All the header files declare it

b) Only few required files declare it

c) All header files declared it if required

d) Only one header file should declare it

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.

7. Whenever a function is declared in a program _____________________

a) extern can be used only in some special cases

b) extern can’t be used

c) function is extern by default

d) it can’t be made extern

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.

8. Even if a variable is not declared as extern, it is extern by default.

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

d) Memory is not allocated for extern variables

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.

10. Which is the correct syntax for extern variable declaration?

a) extern data_type variable_name;

b) extern variable_name;

c) data_type variable_name extern;

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.

11. Which is the correct syntax for extern function declaration?

a) extern function_name(argument_list);
b) extern return_type function_name(argument_list);

c) extern (return_type)function_name(argument_list);

d) return_type extern 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.

12. What will be the output of the program?

extern int var;

int main(void)

var = 10;

var++;

cout<<var;

a) 10

b) 11

c) Run time error

d) Compile time error


View Answer

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 ________________

a) The program can run successfully

b) Also the program should define the extern variable

c) The extern variable must contain two definitions

d) Extern variable can’t be used in the program

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.

14. If extern variable is initialized with the declaration then _______________________

a) Also the header file with definition is required

b) The header file with definition must be included

c) There is no need to include any other header file for definition

d) The extern variable produces compile time error

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.

15. Why are functions extern by default?

a) Because functions are always private

b) Because those are not visible throughout the program

c) Because those can’t be accessed in all parts of the program

d) Because those are visible throughout the program

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.

1. What are inbuilt classes?

a) The predefined classes in a language

b) The classes that are defined by the user

c) The classes which are meant to be modified by the user

d) The classes which can’t be used by the user

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 __________________________

a) Must be included before use

b) Are not necessary to be included for use

c) Are used by the compiler only

d) Can be modified by programmer always

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.

3. What doesn’t inbuilt classes contain?

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

4. Which among the following not an inbuilt class in C++?


a) System

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.

5. What is the InputStream class meant for?

a) To handle all input streams

b) To handle all output streams

c) To handle all input and output streams

d) To handle only input from file

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.

6. Which statement is true for the Array class?

a) Arrays can have variable length

b) The length array can be changed


c) Each class has an associated Array class

d) Arrays can contain different type of values

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.

7. What is the use of Math class?

a) To use the mathematical functions with strings

b) To use the mathematical functions

c) To suppress the use of mathematical functions

d) To complex the calculations

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.

8. DataInputStream is derived from ______________________

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.

9. Which attribute can be used to get the size of an array?

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.

10. Number class can’t manipulate ____________________

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.

12. Which class contain runFinalization() method?

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.

13. What does load(String)::= function do, in System class?

a) Loads dynamic library for a path name

b) Loads all the dynamic libraries

c) Loads all the Number in string format

d) Loads the processor with calculations

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.

14. Which is not a System class variable?

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.

1. What is the use of IO class?

a) To handle all the input operations

b) To handle all the output operations

c) To handle all the input and output operations

d) To handle all the input and output to the standard input

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.

2. IO class provides input and output through ______________________

a) Data streams
b) Serialization

c) File system

d) Data streams, serialization and 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

4. File class is ____________________________

a) An abstract of file representation only


b) An abstract of path names only

c) An abstract which can be used to represent path names or file

d) An abstract which can represent a file in any format

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?

a) A handle for machine specific structure of an open file

b) A handle for program specific structure of an open file

c) A handle for compiler specific structure of an open file

d) A handle for representing device files structure

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 _________________________

a) Gets the input stream from any device file

b) Gets the input stream from any open socket

c) Gets the input stream from any cache


d) Gets the input stream from any open file only

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.

7. What does FilePermission class do?

a) This class is used to give permission rights to a file

b) This class is used to restrict the use of permissions

c) This class is used to represent device access permissions

d) This class is used to represent file access permissions

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.

8. Which class among the following makes incorrect assumptions?

a) LineNumberInputStream

b) LineNumberReader

c) LineReader

d) LineBuffer
View Answer

Answer: a

Explanation: The LineNumberInputStream class makes false assumptions. The false


assumption is that it assumes, all the byte data is a character. Which is actually not the
case, instead the character have one byte memory space.

9. Reader class is _________________

a) Used to read from files

b) Abstract class to read character streams

c) Abstract class to input character streams

d) Used to take input from standard input stream

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.

10. Which class can handle IO class interrupt?

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.

11. StringReader handles _____________________

a) Any character stream

b) A character stream whose source is an array

c) A character stream whose source is character array

d) A character stream whose source is String only

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

Explanation: The encoding that is unsupported in a system can be handled. The


exception handler is UnSupportedEncodingException class. An object of this class can
be created which will catch the exception and handle it.
13. PushBackReader allows the streams to be pushed back to the stream.

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.

14. RandomAccessFile can be used to _______________________

a) Read from a random access file

b) Write to a random access file

c) Read and write to a random access file

d) Restricts read and write to a random access file

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

Explanation: The ObjectStreamClass object can be created to handle serializations. The


class is provided specially for the serializations. It is descriptor like we have a file
descriptor to handle/access files.

1. Which is a true statement for object of String class?

a) Object are immutable

b) Object are mutable

c) Object are created only once

d) Object can’t be created

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.

2. How to declare an object of class String?

a) String object_Name = value;

b) String object_name = new;

c) String object_name= new value;

d) String object_name= value new;


View Answer

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.

3. What does function length do in String class?

a) Returns length of string including null character

b) Returns length of string excluding null character

c) Returns length of substring

d) Returns size of string in bytes

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.

5. If only one parameter is passed to substring function then __________________

a) It returns the character at the specified position

b) It returns the string of length 1 from the specified index

c) It returns the string from specified index till the end

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.

6. If two index are given as argument to substring function then ___________________

a) String of length equal to sum of two arguments is returned

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.

7. String class have a concat() function that is used to _____________________

a) Replace old string by new string

b) Add two strings

c) Append one string at end of another string

d) Remove a string from end of one 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.

8. The function lastIndexOf() is used to ___________________

a) Get the index of last occurrence of specified character in argument

b) Get the index of first occurrence of specified character in argument

c) Get the index of last occurrence of first character in string

d) Get the index of last occurrence of last character of string

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 _________________

a) Case Insensitive, case insensitive

b) Case sensitive, Case insensitive

c) Case sensitive, case sensitive

d) Case insensitive, case sensitive

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.

10. The compareTo() function is used to ________________

a) Compare strings value to string object

b) Compare string value to string value

c) Compare string object to another string object

d) Compare string object to another string value

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.

11. String class provides function toUpper() to _____________________

a) Convert first character to uppercase


b) Convert last character to uppercase

c) Convert the whole string characters to uppercase

d) Convert uppercase to lower and lower to uppercases

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.

12. String trim() function is used to _______________________

a) Remove all the white spaces from the string

b) Remove white space from start of string

c) Remove white space at end of string

d) Remove white space from both the ends of string

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.

13. Function replace() accepts _____________ arguments.

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

c) Second argument indicates the index of the character in first argument

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.

You might also like