250+ TOP MCQs on Static Data Members and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Static Data Members”.

1. Which among the following best defines static variables members?
a) Data which is allocated for each object separately
b) Data which is common to all the objects of a class
c) Data which is common to all the classes
d) Data which is common to a specific method
Answer: b
Clarification: The static data members are made common to all the object of a class. They doesn’t change from object to object. Those are property of class rather than of any individual object.

2. Which keyword should be used to declare static variables?
a) static
b) stat
c) common
d) const
Answer: a
Clarification: The keyword used to declare static variables is static. This is must be used while declaring the static variables. The compiler can make variables static if and only if they are mentioned with static keyword.

3. Any changes made to static data member from one member function _____________
a) Is reflected to only the corresponding object
b) Is reflected to all the variables in a program
c) Is reflected to all the objects of that class
d) Is constant to that function only
Answer: c
Clarification: The changes made from any function to static data member will be a common change for all the other objects also. If the change is made with respect to one object and change is printed from another object, the result will be same.

4. Which is the correct syntax for declaring static data member?
a) static mamberName dataType;
b) dataType static memberName;
c) memberName static dataType;
d) static dataType memberName;
Answer: d
Clarification: The syntax must firstly be mentioned with the keyword static. Then the data type of the member followed by the member name should be given. This is general form of declaring static data members.

5. The static data member ______________________
a) Must be defined inside the class
b) Must be defined outside the class
c) Must be defined in main function
d) Must be defined using constructor
Answer: b
Clarification: The static data members must be defined outside the class. Since these are common to all the objects and should be created only once, they must not be defined in the constructor.

6. The syntax for defining the static data members is __________
a) dataType className :: memberName = value;
b) dataType className : memberName = value;
c) dataType className . memberName = value;
d) dataType className -> memberName =value;
Answer: a
Clarification: The syntax doesn’t contain the static keyword. Since it is already been declared as static inside the class. The data type and the corresponding class name must be there to allocate the variable to a class. The value is assigned using scope resolution operator for the member name.

7. If static data members have to be used inside a class, those member functions _______________
a) Must not be static member functions
b) Must not be member functions
c) Must be static member functions
d) Must not be member function of corresponding class
Answer: c
Clarification: Only the static member functions can access the static data members. The definition of static members is made common and hence the member function should be capable of manipulating the static data members.

8. The static data member __________________________
a) Can be accessed directly
b) Can be accessed with any public class name
c) Can be accessed with dot operator
d) Can be accessed using class name if not using static member function
Answer: d
Clarification: The static data members can be accessed using the class name also. If the member functions is not used or is not to be used then we can call the static data members directly by using its corresponding class name.

9. Which among the following is the correct syntax to access static data member without using member function?
a) className -> staticDataMember;
b) className :: staticDataMember;
c) className : staticDataMember;
d) className . staticDataMember;
Answer: b
Clarification: For accessing the static data members without using the static member functions, the class name can be used. The class name followed by scope resolution, indicating that static data members is member of this class, and then the data member name.

10. Which data members among the following are static by default?
a) extern
b) integer
c) const
d) void
Answer: c
Clarification: The const data members of any class are made static by default. This is an implicit meaning given by the compiler to the member. Since const values won’t change from object to object, hence are made static instead.

11. What is the output of the following program?

class Test
{
	private:	static int x;
	public: static void fun()
	{
		cout << ++x << “ ”;
	}
};
int Test :: x =20;
void main()
{
	Test x;
	x.fun();
	x.fun();
}

a) 20 22
b) 20 21
c) 21 22
d) 22 23
Answer: c
Clarification: The static member is initialized with 20. Then the function is called which used pre-increment and printed value of x. The function is called twice. Hence we get 21 22 as output.

12. Whenever any static data member is declared in a class ______________________
a) Only one copy of the data is created
b) New copy for each object is created
c) New memory location is allocated with each object
d) Only one object uses the static data
Answer: a
Clarification: The static data is same for all the objects. Instead of creating the same data each time an object is created, the compiler created only one data which is accessed by all the objects of the class. This saves memory and reduces redundancy.

13. If object of class are created, then the static data members can be accessed ____________
a) Using dot operator
b) Using arrow operator
c) Using colon
d) Using dot or arrow operator
Answer: d
Clarification: The static data members can be accessed in usual way as other members are accessed using the objects. The dot operator is used generally. Arrow can be used with the pointers.

14. What will be the output of the following program?

class Test
{
	public: Test() 
	{ 
		cout  << "Test's Constructor is Called " << endl;  
	}
};
 
class Result
{
	static Test a;
	public:
	Result() 
	{ 
		cout  << "Result's Constructor is Called " << endl; 
	}
}; 
 
void main() 
{ 
	Result b; 
}

a) Test’s Constructor is Called
b) Result’s Constructor is Called
c) Result’s Constructor Called Test’s Constructor is Called
d) Test’s Constructor Called Result’s Constructor is Called
Answer: b
Clarification: The output is the message printed from the constructor of class Result. There is no inheritance used hence only one constructor is called. Since static members are declared once in class declaration and are not defined. The constructor of class Test will not be called.

15. Which among the following is wrong syntax related to static data members?
a) className :: staticDataMember;
b) dataType className :: memberName =value;
c) static dataType memberName;
d) className : dataType -> memberName;
Answer: d
Clarification: The syntax given in option d doesn’t belong to any particular declaration or definition. First one is to access the static members using the class name. Second is to define the static data outside the class. Third syntax id to declare a data member as static in a class.

250+ TOP MCQs on IO Class and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “IO Class”.

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
Answer: c
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: 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.

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
Answer: c
Clarification: 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
Answer: a
Clarification: 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: c
Clarification: 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
Answer: d
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: 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
Answer: c
Clarification: 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
Answer: b
Clarification: 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.

250+ TOP MCQs on Objects and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Objects”.

1. Which definition best describes an object?
a) Instance of a class
b) Instance of itself
c) Child of a class
d) Overview of a class
Answer: a
Clarification: An object is instance of its class. It can be declared in the same way that a variable is declared, only thing is you have to use class name as the data type.

2. How many objects can be declared of a specific class in a single program?
a) 32768
b) 127
c) 1
d) As many as you want
Answer: d
Clarification: You can create as many objects of a specific class as you want, provided enough memory is available.

3. Which among the following is false?
a) Object must be created before using members of a class
b) Memory for an object is allocated only after its constructor is called
c) Objects can’t be passed by reference
d) Objects size depends on its class data members
Answer: c
Clarification: Objects can be passed by reference. Objects can be passed by value also. If the object of a class is not created, we can’t use members of that class.

4. Which of the following is incorrect?
a) class student{ }s;
b) class student{ }; student s;
c) class student{ }s[];
d) class student{ }; student s[5];
Answer: c
Clarification: The array must be specified with a size. You can’t declare object array, or any other linear array without specifying its size. It’s a mandatory field.

5. The object can’t be __________
a) Passed by reference
b) Passed by value
c) Passed by copy
d) Passed as function
Answer: d
Clarification: Object can’t be passed as function as it is an instance of some class, it’s not a function. Object can be passed by reference, value or copy. There is no term defined as pass as function for objects.

6. What is size of the object of following class (64 bit system)?

class student {  int rollno;  char  name[20];  static int studentno;  };

a) 20
b) 22
c) 24
d) 28
Answer: c
Clarification: The size of any object of student class will be of size 4+20=24, because static members are not really considered as property of a single object. So static variables size will not be added.

7. Functions can’t return objects.
a) True
b) False
Answer: b
Clarification: Functions can always return an object if the return type is same as that of object being returned. Care has to be taken while writing the prototype of the function.

8. How members of an object are accessed?
a) Using dot operator/period symbol
b) Using scope resolution operator
c) Using member names directly
d) Using pointer only
Answer: a
Clarification: Using dot operator after the name of object we can access its members. It is not necessary to use the pointers. We can’t use the names directly because it may be used outside the class.

9. If a local class is defined in a function, which of the following is true for an object of that class?
a) Object is accessible outside the function
b) Object can be declared inside any other function
c) Object can be used to call other class members
d) Object can be used/accessed/declared locally in that function
Answer: d
Clarification: For an object which belongs to a local class, it is mandatory to declare and use the object within the function because the class is accessible locally within the class only.

10. Which among the following is wrong?
a) class student{ }; student s;
b) abstract class student{ }; student s;
c) abstract class student{ }s[50000000];
d) abstract class student{ }; class toppers: public student{ }; topper t;
Answer: b
Clarification: We can never create instance of an abstract class. Abstract classes doesn’t have constructors and hence when an instance is created there is no facility to initialize its members. Option d is correct because topper class is inheriting the base abstract class student, and hence topper class object can be created easily.

11. Object declared in main() function _____________
a) Can be used by any other function
b) Can be used by main() function of any other program
c) Can’t be used by any other function
d) Can be accessed using scope resolution operator
Answer: c
Clarification: The object declared in main() have local scope inside main() function only. It can’t be used outside main() function. Scope resolution operator is used to access globally declared variables/objects.

12. When an object is returned___________
a) A temporary object is created to return the value
b) The same object used in function is used to return the value
c) The Object can be returned without creation of temporary object
d) Object are returned implicitly, we can’t say how it happens inside program
Answer: a
Clarification: A temporary object is created to return the value. It is created because the object used in function is destroyed as soon as the function is returned. The temporary variable returns the value and then gets destroyed.

13. Which among the following is correct?
a) class student{ }s1,s2; s1.student()=s2.student();
b) class student{ }s1; class topper{ }t1; s1=t1;
c) class student{ }s1,s2; s1=s2;
d) class student{ }s1; class topper{ }t1; s1.student()=s2.topper();
Answer: c
Clarification: Only if the objects are of same class then their data can be copied from to another using assignment operator. This actually comes under operator overloading. Class constructors can’t be assigned any explicit value as in option class student{ }s1; class topper{ }t1; s1=t1; and class student{ }s1; class topper{ }t1; s1.student()=s2.topper();.

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

class student{
int marks;
int cgpa;
public: student(int i, int  j){
marks=I;
cgpa=j
}
};

a) student s[3]={ s(394, 9); s(394, 9); s(394,9); };
b) student s[2]={ s(394,9), s(222,5) };
c) student s[2]={ s1(392,9), s2(222,5) };
d) student s[2]={ s[392,9], s2[222,5] };
Answer: b
Clarification: It is the way we can initialize the data members for an object array using parameterized constructor. We can do this to pass our own intended values to initialize the object array data.

15. Object can’t be used with pointers because they belong to user defined class, and compiler can’t decide the type of data may be used inside the class.
a) True
b) False
Answer: b
Clarification: The explanation given is wrong because object can always be used with pointers like with any other variables. Compiler doesn’t have to know the structure of the class to use a pointer because the pointers only points to a memory address/stores that address.

250+ TOP MCQs on Member Functions and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Member Functions”.

1. Which among the following best describes member functions?
a) Functions which are defined within the class
b) Functions belonging a class
c) Functions in public access of a class
d) Functions which are private to class
Answer: b
Clarification: We can’t say that only functions that are defined inside class are member functions. There can be some inherited functions. Though they doesn’t belong to the class but are property of the objects once inheritance is used. So the nearest definition is functions belonging to a class.

2. How many types of member functions are generally there in C++?
a) 2
b) 3
c) 4
d) 5
Answer: d
Clarification: There are 5 types of member functions that are generally provided in C++. Namely, simple, static, const, inline and friend member functions. Member functions are specific to classes.

3. How can a static member function be called in the main function?
a) Using dot operator
b) Using arrow operator
c) Using dot or arrow operator
d) Using dot, arrow or using scope resolution operator with class name
Answer: d
Clarification: The member functions can be called using only the dot operator or the arrow operator. But the static members can be called using directly the class name followed by the scope resolution operator and static member function name. This is useful when you don’t have any object to call the member.

4. What are inline member functions?
a) Member functions which can be called without object
b) Member functions whose definition is expanded in place of its call
c) Member functions whose definition is faster than simple function
d) Member function which is defined in single line
Answer: b
Clarification: The member functions whose definition is expanded at the call, and no jump to function and return happened, are termed as inline functions. This is used to make the program faster and more efficient.

5. What happens if non static members are used in static member function?
a) Compile time error
b) Runtime error
c) Executes fine
d) Executes if that member function is not used
Answer: a
Clarification: There must be specific memory space allocated for the data members before the static member functions uses them. But the space is not reserved if object is not declared. Hence only if static members are not used, it leads to compile time error.

6. Static member functions _____________
a) Contains “this” pointer for data members
b) Contains “this” pointer if used for member functions
c) Doesn’t contain “this” pointer
d) Doesn’t contain “this” pointer if member functions are referred
Answer: c
Clarification: The static member functions doesn’t contain “this” pointer. Static member functions can’t be defined as const or volatile also. These are restrictions on static member functions.

7. How to access members of the class inside a member function?
a) Using this pointer only
b) Using dot operator
c) Using arrow operator
d) Used directly or with this pointer
Answer: d
Clarification: The members of a class can be used directly inside a member function. We can use this pointer when there is a conflict between data members of class and arguments/local function variable names.

8. For overloading “( )”, “[ ]” or “->” operators, a class __________
a) Must use static member functions
b) Must use non-static member functions
c) Must be non-static member and should not be friend of class
d) Must use static member function or a friend member function
Answer: c
Clarification: For overloading those operators for a class, the class must use non-static member function so that doesn’t remain common to all the objects, and each object can use it independently. The friend functions is also restricted so as to keep the security of data.

9. If a virtual member function is defined ___________
a) It should not contain any body and defined by subclasses
b) It must contain body and overridden by subclasses
c) It must contain body and be overloaded
d) It must not contain any body and should not be derived
Answer: a
Clarification: The virtual functions are defined using virtual keyword. These are made in order to make all the classes to define them as the class gets inherited. Increases code understanding.

10. Member functions of a generic class are _____________
a) Not generic
b) Automatically generic
c) To be made generic explicitly
d) Given default type as double
Answer: b
Clarification: When generic type is used in a class, the functions are automatically generic. This is so because the functions would use the same type as defined to make the class generic. The functions will get to know the type of data as soon as the generic class is used. It’s inbuilt feature.

11. Member function of a class can ____________
a) Access all the members of the class
b) Access only Public members of the class
c) Access only the private members of the class
d) Access subclass members
Answer: a
Clarification: The member functions has access to all the members of the class. Whenever data members of a class, which might be private, have to be modified, we make use of these member functions. This is more secure way to manipulate data.

12. Which among the following is proper syntax for class given below?

class A
{ 
	int a,b;
	public : void disp();
}

a) void disp::A(){ }
b) void A::disp(){ }
c) void A:disp() { cout<d) void disp:A(){ cout<Answer: b
Clarification: The syntax in option void A::disp(){ } is correct. We use scope resolution to represent the member function of a class and to write its definition. It is not necessary for a function to have anything in its definition.

13. A member function can _______________ of the same class.
a) Call other member functions
b) Call only private member functions
c) Call only static member functions
d) Call only const member functions
Answer: a
Clarification: We can call one function inside another function to access some data of class. A public member function can be used to call a private member function which directly manipulates the private data of class.

14. Which member function doesn’t require any return type?
a) Static
b) Constructor
c) Const
d) Constructor and destructor
Answer: d
Clarification: All the member functions work same as normal functions with syntax. But the constructor and destructor are also considered as member functions of a class, and they never have any data type.

15. Which among the following is not possible for member function?
a) Access protected members of parent class
b) Definition without return type
c) Access public members of subclass
d) Access static members of class
Answer: c
Clarification: A member function of a class can only have the access to the members of its own class and parent classes if inheritance used. Otherwise a member function can never access the members of a subclass. Accessing static members of a class is possible by normal and static member functions.

250+ TOP MCQs on Multilevel Inheritance and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Multilevel Inheritance”.

1. Which among the following best defines multilevel inheritance?
a) A class derived from another derived class
b) Classes being derived from other derived classes
c) Continuing single level inheritance
d) Class which have more than one parent
Answer: b
Clarification: Only if the class is being derived from other derived class, it can be called as multilevel inheritance. If a class is derived from another class, it is single level inheritance. There must be more than one level of inheritance.

2. If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class constructor will be called first if the object of E or D is created?
a) A
b) B
c) C
d) A and B
Answer: a
Clarification: A is parent of all other classes indirectly. Since A is parent of B and B is parent of C and so on till E. Class A constructor will be called first always.

3. If there are 3 classes. Class C is derived from class B and B is derived from A, Which class destructor will be called at last if object of C is destroyed.
a) A
b) B
c) C
d) All together
Answer: a
Clarification: The destructors are called in the reverse order of the constructors being called. Hence in multilevel inheritance, the constructors are created from parent to child, which leads to destruction from child to parent. Hence class A destructor will be called at last.

4. Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?
a) Class at 1st level
b) Class 2nd last level
c) Class at 5th level
d) All with same abstraction
Answer: a
Clarification: The class with highest degree of abstraction will be the class at the 1st level. You can look at a simple example like, a CAR is more abstract than SPORTS CAR class. The level of abstraction decrease with each level as more details comes out.

5. If all the classes use private inheritance in multilevel inheritance then ______________
a) It will not be called multilevel inheritance
b) Each class can access only non-private members of its parent
c) Each subsequent class can access all members of previous level parent classes
d) None of the members will be available to any other class
Answer: b
Clarification: The classes will be able to access only the non-private members of its parent class. The classes are using private inheritance, hence all the members of the parent class become private in the derived class. In turn those won’t be allowed for further inheritance or direct access outside the class.

6. Multilevel inheritance allows _________________ in the program.
a) Only 7 levels of inheritance
b) At least 7 levels of inheritance
c) At most 16 levels of inheritance
d) As many levels of inheritance as required
Answer: d
Clarification: The multilevel inheritance allows any number of levels of inheritance. This is the maximum flexibility feature to make the members available to all the new classes and to add their own functionalities. The code reusability is used too.

7. What is the minimum number of levels for a implementing multilevel inheritance?
a) 1
b) 2
c) 3
d) 4
Answer: c
Clarification: There must be at least 3 levels of inheritance. Otherwise if less, it will be single level inheritance or would have got no inheritance implemented. There must be a derived class from which another class is derived.

8. In multilevel inheritance one class inherits _______________
a) Only one class
b) More than one class
c) At least one class
d) As many classes as required
Answer: a
Clarification: The classes inherit only from one class. This continues as each class inherits only one class. There should not be any class that inherits from two or more classes or which have more than one subclass.

9. All the classes must have all the members declared private to implement multilevel inheritance.
a) True
b) False
Answer: b
Clarification: There is no mandatory rule to make the members private for multilevel inheritance. Moreover, if all the classes have only the private members then there won’t be any member to get inherited. Hence the working will be of no use.

10. Can abstract classes be used in multilevel inheritance?
a) Yes, always
b) Yes, only one abstract class
c) No, abstract class doesn’t have constructors
d) No, never
Answer: a
Clarification: The abstract classes can always be used in multilevel inheritance. The only condition that may arise is that all the undefined functions must be defined in subclasses. There must not be any undefined function.

11. How many abstract classes can be used in multilevel inheritance?
a) Only 1
b) Only 2
c) At least one less than number of levels
d) Can’t be used
Answer: c
Clarification: At least one class must implement all the undefined functions. Hence there must be at least one class which is not abstract. That is at least one less than number of levels.

12. If all the classes used parameterized constructors and no default constructor then ___________
a) The object of lower level classes can’t be created
b) Object of lower level classes must call parent class constructors explicitly
c) Object of lower level classes must define all the default constructors
d) Only object of first class can be created, which is first parent
Answer: b
Clarification: Each class constructor must be called before creating the object of any subclass. Hence it will be mandatory to call the constructors of parent classes explicitly with parameters. This will make all the previous class member be initialized and then the class in use will be able to create the object.

13. In multilevel inheritance, which is the most significant feature of OOP used?
a) Code readability
b) Flexibility
c) Code reusability
d) Code efficiency
Answer: c
Clarification: The classes using multilevel inheritance will use the code in all the subsequent subclasses if available. Hence the most significant feature among the options given is code reusability. This feature is generally intended to use the data values and reuse the redundant functions.

14. Does following code show multiple inheritance?

 
class A
{
	int a;
};
class B
{
	int b;
};
class C:public A, public B
{
	int c;
};
class D:public C
{
	int d;
};

a) Yes, class C and class D
b) Yes, All together it’s multilevel
c) No, 4 classes are used
d) No, multiple inheritance is used with class A, B and C
Answer: d
Clarification: Since multiple inheritance is used to derive class C and then class D is derived from class C. This is not multilevel inheritance. The classes should derive from single class. This is actually hybrid inheritance.

15. Is it compulsory for all the classes in multilevel inheritance to have constructors defined explicitly if only last derived class object is created?
a) Yes, always
b) Yes, to initialize the members
c) No, it not necessary
d) No, Constructor must not be defined
Answer: c
Clarification: It’s not mandatory to define the constructors explicitly. Default constructor will always be provided by the compiler itself if none another constructor is defined in those classes. If explicit default constructor is defined it will be used.

250+ TOP MCQs on Static Member Functions and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Static Member Functions”.

1. Which among the following is correct definition for static member functions?
a) Functions created to allocate constant values to each object
b) Functions made to maintain single copy of member functions for all objects
c) Functions created to define the static members
d) Functions made to manipulate static programs
Answer: b
Clarification: The functions which are made common, with respect to definition and data usage, to all the objects. These functions are able to access the static data members of a class.

2. The static member functions __________________
a) Have access to all the members of a class
b) Have access to only constant members of a class
c) Have access to only the static members of a class
d) Have direct access to all other class members also
Answer: c
Clarification: The static member functions are common for all the objects. These functions can use only the static members of a class in which those are defined. This is because other members change with respect to each object created.

3. The static member functions ____________________
a) Can be called using class name
b) Can be called using program name
c) Can be called directly
d) Can’t be called outside the function
Answer: a
Clarification: The static members can be accessed using class name also. This is because the static members remain common to all the objects. Hence objects are not required.

4. Which is correct syntax to access the static member functions with class name?
a) className . functionName;
b) className -> functionName;
c) className : functionName;
d) className :: functionName;
Answer: d
Clarification: The scope resolution operator must be used to access the static member functions with class name. This indicates that the function belongs to the corresponding class.

5. Which among the following is not applicable for the static member functions?
a) Variable pointers
b) void pointers
c) this pointer
d) Function pointers
Answer: c
Clarification: Since the static members are not property of objects, they doesn’t have this pointer. Every time the same member is referred from all the objects, hence use of this pointer is of no use.

6. Which among the following is true?
a) Static member functions can’t be virtual
b) Static member functions can be virtual
c) Static member functions can be declared virtual if it is pure virtual class
d) Static member functions can be used as virtual in Java
Answer: a
Clarification: The static member functions can’t be virtual. This is a restriction on static member functions, since the definition should not change or should not be overridden by any other function of derived class. The static members must remain same for all the objects.

7. The static members are ______________________
a) Created with each new object
b) Created twice in a program
c) Created as many times a class is used
d) Created and initialized only once
Answer: d
Clarification: The static members are created only once. Then those members are reused whenever called or invoked. Memory is allocated only once.

8. Which among the following is true?
a) Static member functions can be overloaded
b) Static member functions can’t be overloaded
c) Static member functions can be overloaded using derived classes
d) Static member functions are implicitly overloaded
Answer: b
Clarification: The static member functions can’t be overloaded because the definition must be the same for all the instances of a class. If an overloaded function have many definitions, none of them can be made static.

9. The static member functions _______________
a) Can’t be declared const
b) Can’t be declared volatile
c) Can’t be declared const or volatile
d) Can’t be declared const, volatile or const volatile
Answer: d
Clarification: The static member functions can’t be made const, since any object or class itself should be capable of making changes to the function. And the function must retain all changes common to all the objects.

10. Which keyword should be used to declare the static member functions?
a) static
b) stat
c) const
d) common
Answer: a
Clarification: The member functions which are to be made static, must be preceded with the keyword static. This indicates the compiler to make the functions common to all the objects. And a new copy is not created with each of the new object.

11. The keyword static is used _______________
a) With declaration inside class and with definition outside the class
b) With declaration inside class and not with definition outside the class
c) With declaration and definition wherever done
d) With each call to the member function
Answer: b
Clarification: The keyword is used only inside the class while declaring the static member. Outside the class, only definition with proper syntax is given. There is no need of specifying the keyword static again.

12. Which among the following can’t be used to access the members in any way?
a) Scope resolution
b) Arrow operator
c) Single colon
d) Dot operator
Answer: c
Clarification: The single colon can’t be used in any way in order to access the static members of a class. Other symbols can be used according to the code and need.

13. We can use the static member functions and static data member __________________
a) Even if class object is not created
b) Even if class is not defined
c) Even if class doesn’t contain any static member
d) Even if class doesn’t have complete definition
Answer: a
Clarification: The static members are property of class as a whole. There is no need of specific objects to call static members. Those can be called directly or with class name.

14. The static data member _________________
a) Can be mutable
b) Can’t be mutable
c) Can’t be integer
d) Can’t be characters
Answer: b
Clarification: The static data members can never be mutable. There copies are not made. Since those are common and created only once.

15. If static data member are made inline, ______________
a) Those should be initialized outside the class
b) Those can’t be initialized with the class
c) Those can be initialized within the class
d) Those can’t be used by class members
Answer: c
Clarification: Since the members are created once and are common for all the instances, those can be initialized inside the class. Those doesn’t change with each object being created hence can be defined inside the class once for all.