Object Oriented MCQ Number 01261

Object Oriented MCQ Set 1

1. Which among the following is true for class exceptions?
a) Only base class can give rise to exceptions
b) Only derived class can give rise to exceptions
c) Either base class or derived class may produce exceptions
d) Both base class and derived class may produce exceptions

Answer

Answer: d [Reason:] It’s not mandatory that either base class or derived class can give rise to exceptions. The exceptions might get produced from any class. The exceptions depends on code.

2. If both base and derived class caught exceptions ________
a) Then catch block of derived class must be defined before base class
b) Then catch block of base class must be defined before the derived class
c) Then catch block of base and derived classes doesn’t matter
d) Then catch block of base and derived classes are not mandatory to be defined

Answer

Answer: a [Reason:] It is a condition for writing the catch blocks for base and derived classes. It is mandatory to write derived class catch block first because the errors produced by the derived class must be handled first.

3. Which among the following is true?
a) If catch block of base class is written first, it is compile time error
b) If catch block of base class is written first, it is run time error
c) If catch block of base class is written first, derived class catch block can’t be reached
d) If catch block of base class is written first, only derived class catch block is executed

Answer

Answer: c [Reason:] If the catch block of the base class is defined first and then the derived class catch block is given. The code becomes unreachable. Hence the derived class catch block must be written first.

4. The catching of base class exception _____ in java.
a) After derived class is not allowed by compiler
b) Before derived class is not allowed by compiler
c) Before derived class is allowed
d) After derived class can’t be done

Answer

Answer: b [Reason:] The catching of base class exception before derived class is not allowed in java. The compiler itself doesn’t allow this declaration. It produces an error.

5. If catching of base class exception is done before derived class in C++ ____
a) It gives compile time error
b) It doesn’t run the program
c) It may give warning but not error
d) It always gives compile time error

Answer

Answer: c [Reason:] The compiler in C++ doesn’t identify this as compile time error and allows the execution of the program. But, the compiler may give some warning related to the catch block sequence or code unreachable.

6. How many catch blocks can a class have?
a) Only 1
b) 2
c) 3
d) As many as required

Answer

Answer: d [Reason:] There are many type of exceptions that may arise while running a code. And each catch block can handle only one exception. Hence there can be as many catch blocks as required.

7. Since which version of java is multiple exception catch was made possible?
a) Java 4
b) Java 5
c) Java 6
d) Java 7

Answer

Answer: d [Reason:] None of the languages used to support multiple exception catch in a single catch block. Since java 7 the feature was added to catch more than one exceptions in one catch block.

8. To catch more than one exception in one catch block, how are the exceptions separated in the syntax?
a) Vertical bar
b) Hyphen
c) Plus
d) Modulus

Answer

Answer: a [Reason:] Just the way we separate the arguments in a function definition using comma. Here we separate the exceptions by using a vertical bar or we call it pipe symbol sometimes. This is just a convention followed to separate different exception list.

9. If a catch block accepts more than one exceptions then ______
a) The catch parameters are not final
b) The catch parameters are final
c) The catch parameters are not defined
d) The catch parameters are not used

Answer

Answer: b [Reason:] The catch parameters are made final. This is to ensure that the parameters are not changed inside the catch block. Hence those retain their values.

10. Which among the following handles the undefined class in program?
a) ClassNotFound
b) NoClassException
c) ClassFoundException
d) ClassNotFoundException

Answer

Answer: d [Reason:] It is the exception handler that handles the exceptions when the class used is not found in the program. This is done to handle all the undefined class exceptions. This can be due to a command line error.

11. If classes produce some exceptions, then ______
a) Their respective catch block must be defined
b) Their respective catch blocks are not mandatory
c) Their catch blocks should be defined inside main function
d) Their catch blocks must be defined at the end of program

Answer

Answer: a [Reason:] The catch blocks must be defined. This is to ensure that all the exceptions related to the classes are handled by the program code and the program doesn’t terminate unexpectedly.

12. Which among the following is true?
a) Only the base class catch blocks are important
b) Only the derived class catch blocks are important
c) Both the base and derived class catch blocks are important
d) If base and derived classes both produce exceptions, program doesn’t run

Answer

Answer: c [Reason:] The purpose of exception handling is to handle the unexpected errors in the program. If base class might produce some error then its catch block must be given and if the derived class might produce some error then it must be given a specific catch block too.

13. Which is the necessary condition to define the base and derived class catch blocks?
a) Base class catch should be defined first
b) Derived class catch should be defined first
c) Catch block for both the classes must not be defined
d) Catch block must be defined inside main function

Answer

Answer: b [Reason:] The derived class catch blocks must be defined prior to the base class catch block. This is to ensure that all the catch boxes are reachable. If not done, the code might become unreachable which in turn makes the program prone to errors.

14. Only the base class catch box can handle more than one exception in single block.
a) True
b) False

Answer

Answer: b [Reason:] There is no specific condition that states that only base class catch box can handle more than one exception in single box. Even the derived class catch clocks can handle more than one exceptions.

15. Which condition among the following might result in memory exception?
a) False if conditions
b) Nested if conditions that are all false
c) Infinite loops
d) Loop that runs exactly 99 times

Answer

Answer: c [Reason:] The infinite loops doesn’t stop running once started. There must be a way to stop the loop but that is always an improper termination. Infinite loops may keep on using more memory and hence would result in memory error.

Object Oriented MCQ Set 2

1. Which among the following is the main characteristic of class?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Object creation

Answer

Answer: b [Reason:] The classes are made to encapsulate the data and properties that are most similar and can be grouped together inside a single class. This single class can represent all of those features by creating its instances.

2. To group all the brands of cars, what should be used?
a) Class
b) Structure
c) Function
d) Object

Answer

Answer: a [Reason:] A class can be used to group all the brands of cars. The Different brands may have different properties but all will have some common properties like number of wheels and doors, accessories etc. All of those properties can be grouped into a single class representing all the cars.

3. If a class have two data members and two functions to add those two numbers and to subtract them, which among the following is most efficient if the programmer wants to implement multiplication too?
a) Define a public function which multiplies two numbers
b) Define a public function that returns values of two data members
c) Define a private function which multiplies two numbers
d) Define a private function that returns values of two data members

Answer

Answer: b [Reason:] The best choice would be to define a public member function that returns the values of two data members of the class. This way we can implement any operation on those data members. Also there won’t be any need to modify the program and to add new functions for each new operation.

4. If a database have to be maintained using OOP, to store the details of each employee in a company, which would be the best choice among the following?
a) Define a class to store details of each employee
b) Define a structure to store details of each employee
c) Define separate variable for each detail
d) Define a generic type to store string and number details

Answer

Answer: a [Reason:] A single class can be defined that represents a single employee of a company. The specific type of functions that can be applied to specific employees can be put into another class that is derived from the existing class.

5. Which class represents the most abstracted information?
a) Nested
b) Derived
c) Enclosed
d) Base

Answer

Answer: d [Reason:] The base classes are the most abstracted part of information. A base class having many other derived classes would have a bigger overview of all the other derived classes. Hence the base classes have the most abstract information.

6. Which among the following is an advantage of using classes over structures of C?
a) Functions are restricted
b) Functions can’t be defined
c) Fuctions can also be encapsulated
d) Functions can have more security

Answer

Answer: c [Reason:] The functions are also made easy to be encapsulated inside a class. In structures, only the data members were allowed to be encapsulated. Hence classes can represent an entity in a better way.

7. Which among the follow is a feature of class?
a) Object orientation
b) Procedure orientation
c) Both object and procedure orientation
d) Neither object nor procedure orientation

Answer

Answer: a [Reason:] Thee use of classes feature the object oriented programming. The OOP concept can be implemented by using class and their objects. Procedures orientation is not feature of OOP.

8. Class is _______ of an object.
a) Basic function definition
b) Detailed description with values
c) Blueprint
d) Set of constant values

Answer

Answer: c [Reason:] The class is an overview for an object. It contains the basic details map of data that an object will contain. An object is independent representation of class.

9. In which case the classes can be used to make more efficient program?
a) To define a function that is called frequently in a program
b) To structure data that is most similar
c) To group the most similar data and operations
d) To define a blueprint that shows memory location of data

Answer

Answer: c [Reason:] The classes would be more suitable to use in case where we need to group the most similar data and operations. The data can be represented as data members of class and operations as member functions of class. This is indirectly encapsulation feature.

10. What is the use of inbuilt classes?
a) Provide predefined data
b) Provede predefined functions
c) Provide predefined data and functions
d) Provide predeclared data to be overridden

Answer

Answer: c [Reason:] The data that is constant or is always the same initially for use can be provided by some inbuilt classes. The functions that are mostly used are also provided by the inbuilt classes. The data and functions can be used by including the corrosponding header file or library.

11.Which feature is exhibited by the inbuilt classes?
a) Code reusability
b) Code effeciency
c) Code readability
d) Code reusability, effeciency and readability

Answer

Answer: d [Reason:] The code is reusable as the functions which are already written, can be used anytime required. The code becomes easier to read. Also, the code is efficient as there is no need to assign any external code.

12. Why do we use user defined classes?
a) To desined a user intended code
b) To model real world objects
c) To desing the interfaces
d) To model the functions

Answer

Answer: b [Reason:] The primitive classes are not sufficient for the programming complex algorithms. Some user defined classes are required to represent a real world object and to define a blueprint of what the class should actually contain. The user defined classes are as per the requirements and need of user.

13. Why do classes use accessor methods?
a) To make public data accessible to client
b) To make public data private to client
c) To make private data public for whole program
d) To make private data accessible to the client

Answer

Answer: d [Reason:] The private data of a class is usually not accessible. But the data can be accessed by the user using accessor functions. These functions allows the user to get the data stored as private in a class.

14. Why do classes use mutator methods?
a) Allows client to modify the program
b) Allows client to modify/write the private members
c) Allows servers to access all the private data
d) Allows servers to access only protected members

Answer

Answer: b [Reason:] The client can have rights to access a file and write something to it. This is mandatory to keep the private data updated. Also it is an advantage over the use of hidden class members.

15. Which among the following is the most abstract form of class?
a) Cars
b) BMW cars
c) Big cars
d) Small cars

Answer

Answer: a [Reason:] The most abstract class is class Cars. The class Cars is most general form of all other cars. If it is a brand of car, it comes under car. If it is type of car then alsoo it comes under Cars.

Object Oriented MCQ Set 3

1. Which of the following is not type of class?
a) Abstract Class
b) Final Class
c) Start Class
d) String Class

Answer

Answer: c [Reason:] Only 9 types of classes are provided in general, namely, abstract, final, mutable, wrapper, anonymous, input-output, string, system, network. We may further divide the classes into parent class and sub class if inheritance is used.

2. Class is pass by _______
a) Value
b) Reference
c) Value or Reference, depending on program
d) Copy

Answer

Answer: b [Reason:] Classes are pass by reference, and the structures are pass by copy. It doesn’t depend on program.

3. What is default access specifier for data members or member functions declared within a class without any specifier, in C++ ?
a) Private
b) Protected
c) Public
d) Depends on compiler

Answer

Answer: a [Reason:] The data members and member functions are Private by default in C++ classes, if none of the access specifier is used. It is actually made to increase the privacy of data.

4. Which is most appropriate comment on following class definition :

class Student 
{
    int a; 
    public : float a; 
};

a) Error : same variable name can’t be used twice
b) Error : Public must come first
c) Error : data types are different for same variable
d) It is correct

Answer

Answer: a [Reason:] Same variable can’t be defined twice in same scope. Even if the data types are different, variable name must be different. There is no rule like Public member should come first or last.

5. Which is known as generic class?
a) Abstract class
b) Final class
c) Template class
d) Efficient Code

Answer

Answer: c [Reason:] Template classes are known to be generic classes because those can be used for any data type value and the same class can be used for all the variables of different data types.

6. Size of a class is :
a) Sum of size of all the variables declared inside the class
b) Sum of size of all the variables along with inherited variables in the class
c) Size of largest size of variable
d) Classes doesn’t have any size

Answer

Answer: d [Reason:] Classes doesn’t have any size, actually the size of object of the class can be defined. That is done only when an object is created and its constructor is called.

7. Which class can have member functions without their implementation?
a) Default class
b) String class
c) Template class
d) Abstract class

Answer

Answer: d [Reason:] Abstract classes can have member functions with no implementation, where the inheriting sub classes must implement those functions.

8. Which of the following describes a friend class?
a) Friend class can access all the private members of the class, of which it is a friend
b) Friend class can only access protected members of the class, of which it is a friend
c) Friend class don’t have any implementation
d) Friend class can’t access any data member of another class but can use it’s methods

Answer

Answer: a [Reason:] A friend class can access all the private members of another class, of which it is friend. It is a special class provided to use when you need to reuse the data of a class but don’t want that class to have those special functions.

9. What is scope of a class nested inside another class?
a) Protected scope
b) Private scope
c) Global scope
d) Depends on access specifier and inheritance used

Answer

Answer: d [Reason:] It depends on the access specifier and the type of inheritance used with the class, because if the class is inherited then the nested class can be used by subclass too, provided it’s not of private type.

10. Class with main() function can be inherited (True/False)
a) True
b) False

Answer

Answer: a [Reason:] The class containing main function can be inherited and hence the program can be executed using the derived class names also in java.

11. Which among the following is false, for member function of a class?
a) All member functions must be defined
b) Member functions can be defined inside or outside the class body
c) Member functions need not be declared inside the class definition
d) Member functions can be made friend to another class using friend keyword

Answer

Answer: c [Reason:] Member functions must be declared inside class body, thought the definition can be given outside the class body. There is no way to declare the member functions inside the class.

12. Which syntax for class definition is wrong?
a) class student{ };
b) student class{ };
c) class student{ public: student(int a){ } };
d) class student{ student(int a){} };

Answer

Answer: b [Reason:] Keyword class should come first. Class name should come after keyword class. Parameterized constructor definition depends on programmer so it can be left empty also.

13. Which of the following pairs are similar?
a) Class and object
b) Class and structure
c) Structure and object
d) Structure and functions

Answer

Answer: b [Reason:] Class and structure are similar to each other. Only major difference is that a structure doesn’t have member functions whereas the class can have both data members and member functions.

14. Which among the following is false for class features?
a) Classes may/may not have both data members and member functions
b) Class definition must be ended with a colon
c) Class can have only member functions with no data members
d) Class is similar to union and structures

Answer

Answer: b [Reason:] Class definition must end with a semicolon, not colon. Class can have only member functions in its body with no data members.

15. Instance of which type of class can’t be created?
a) Anonymous class
b) Nested class
c) Parent class
d) Abstract class

Answer

Answer: d [Reason:] Instance of abstract class can’t be created as it will not have any constructor of its own, hence while creating an instance of class, it can’t initialize the object members. Actually the class inheriting the abstract class can have its instance, because it will have implementation of all members.

Object Oriented MCQ Set 4

1. Which among the following is called first, automatically, whenever an object is created?
a) Class
b) Constructor
c) New
d) Trigger

Answer

Answer: b [Reason:] Constructors are the member functions which are called automatically whenever an object is created. It is a mandatory functions to be called for an object to be created as this helps in initializing the object to a legal initial value for the class.

2. Which among the following is not a necessary condition for constructors?
a) Its name must be same as that of class
b) It must not have any return type
c) It must contain a definition body
d) It can contains arguments

Answer

Answer: c [Reason:] Constructors are predefined implicitly, even if the programmer doesn’t define any of them. Even if the programmer declares a constructor, it’s not necessary that it must contain some definition.

3. Which among the following is correct?
a) class student{ public: int student(){} };
b) class student{ public: void student (){} };
c) class student{ public: student{}{} };
d) class student{ public: student(){} };

Answer

Answer: d [Reason:] The constructors must not have any return type. Also, the body may or may not contain any body. Defining default constructor is optional, if you are not using any other constructor.

4. In which access should a constructor be defined, so that object of the class can be created in any function?
a) Public
b) Protected
c) Private
d) Any access specifier will work

Answer

Answer: a [Reason:] Constructor function should be available to all the parts of program where the object is to be created. Hence it is advised to define it in public access, so that any other function is able to create objects.

5. How many types of constructors are available for use in general (with respect to parameters)?
a) 2
b) 3
c) 4
d) 5

Answer

Answer: a [Reason:] Two types of constructors are defined generally, namely, default constructor and parameterized constructor. Default constructor is not necessary to be defined always.

6. If a programmer defines a class and defines a default valued parameterized constructor inside it.
He has not defined any default constructor. And then he try to create the object without passing arguments, which among the following will be correct?
a) It will not create the object (as parameterized constructor is used)
b) It will create the object (as the default arguments are passed )
c) It will not create the object ( as the default constructor is not defined )
d) It will create the object ( as at least some constructor is defined )

Answer

Answer: b [Reason:] It will create the object without any problem, because the default arguments use the default value if no value is passed. Hence it is equal to default constructor with zero parameters. But it will not create the object if signature doesn’t match.

7. Default constructor must be defined, if parameterized constructor is defined and the object is to be created without arguments.
a) True
b) False

Answer

Answer: a [Reason:] If the object is create without arguments and only parameterized constructors are used, compiler will give an error as there is no default constructor defined. And some constructor must be called so as to create an object in memory.

8. If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called?
a) Constructor of C then B, finally of A
b) Constructor of A then C, finally of B
c) Constructor of C then A, finally B
d) Constructor of A then B, finally C

Answer

Answer: d [Reason:] While creating the object of class C, its constructor would be called by default. But, if the class is inheriting some other class, firstly the parent class constructor will be called so that all the data is initialized that is being inherited.

9. In multiple inheritance, if class C inherits two classes A and B as follows, which class constructor will be called first:

class A{ };
class B{ };
class C: public A, public B{  };

a) A()
b) B()
c) C()
d) Can’t be determined

Answer

Answer: a [Reason:] Constructor of class A will be called first. This is because the constructors in multiple inheritance are called in the sequence in which they are written to be inherited. Here A is written first, hence it is called first.

10. Which among the following is true for copy constructor?
a) The argument object is passed by reference
b) It can be defined with zero arguments
c) Used when an object is passed by value to a function
d) Used when a function returns an object

Answer

Answer: b [Reason:] It can’t be defined with zero number of arguments. This is because to copy one object to another, the object must be mentioned so that compiler can take values from that object.

11. If the object is passed by value to a copy constructor:
a) Only public members will be accessible to be copied
b) That will work normally
c) Compiler will give out of memory error
d) Data stored in data members won’t be accessible

Answer

Answer: c [Reason:] Compiler runs out of memory. This is because while passing the argument by value, a constructor of the object will be called. That in turn called another object constructor for values, and this goes on. This is like a constructor call to itself, and this goes on infinite times, hence it must be passed by reference, so that the constructor is not called.

12. Which object will be created first?

class student 
{  
    int marks;
};
student s1, s2, s3;

a) s1 then s2 then s3
b) s3 then s2 then s1
c) s2 then s3 then s1
d) All are created at same time

Answer

Answer: a [Reason:] The objects are created in the sequence of how they are written. This happens because the constructors are called in the sequence of how the objects are mentioned. This is done in sequence.

13. Which among the following helps to create a temporary instance?
a) Implicit call to a default constructor
b) Explicit call to a copy constructor
c) Implicit call to a parameterized constructor
d) Explicit call to a constructor

Answer

Answer: d [Reason:] Explicit call to a constructor can let you create temporary instance. This is because the temporary instances doesn’t have any name. Those are deleted from memory as soon as their reference is removed.

14. Which among the following is correct for the class defined below?

class student
{
int marks;
public: student(){}
	student(int x)
{ 
		marks=x; 
}
};
main()
{
student s1(100);
student s2();
student s3=100;
return 0;

a) Object s3, syntax error
b) Only object s1 and s2 will be created
c) Program runs and all objects are created
d) Program will give compile time error

Answer

Answer: c [Reason:] It is a special case of constructor with only 1 argument. While calling a constructor with one argument, you are actually implicitly creating a conversion from the argument type to the type of class. Hence you can directly specify the value of that one argument with assignment operator.

15. For constructor overloading, each constructor must differ in _____ and ____
a) Number of arguments and type of arguments
b) Number of arguments and return type
c) Return type and type of arguments
d) Return type and definition

Answer

Answer: a [Reason:] Each constructor must differ in the number of arguments it accepts and the type of arguments. This actually defines the constructor signature. This helps to remove the ambiguity and define a unique constructor as required.

Object Oriented MCQ Set 5

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

Answer

Answer: b [Reason:] 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

Answer

Answer: c [Reason:] 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. (True/False)
a) True
b) False

Answer

Answer: a [Reason:] 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.

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 same name as that of class

Answer

Answer: d [Reason:] The constructors must have 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)

Answer

Answer: b [Reason:] 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

Answer

Answer: d [Reason:] 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()

Answer

Answer: c [Reason:] 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

Answer

Answer: b [Reason:] 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

Answer

Answer: a [Reason:] 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

Answer

Answer: d [Reason:] 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);

Answer

Answer: a [Reason:] 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 which 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);

Answer

Answer: c [Reason:] 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

Answer

Answer: c [Reason:] 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

Answer

Answer: d [Reason:] 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

Answer

Answer: b [Reason:] 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.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.