Object Oriented Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Object Oriented Programming MCQ (Multiple Choice Questions)

 Que- When is downcating 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 


Ans- To compare two objects  


Que- 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 


Ans- Because inheritance follows is-a relationship  


Que- What is 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 


Ans- Allocates memory for an object or array and returns a particular pointer  


Que- 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 


Ans- Add new vtable slot entries  


Que- 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 


Ans- Either throws an exception or returns zero  


Que- 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 


Ans- _set_new_handler  


Que- 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 


Ans- After the allocation of memory  


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


Ans- char (*pchar)[10] = new char[][10];  


Que- 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 


Ans- Type name can't contain const, volatile, class declaration or enumerations  


Que- 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 


Ans- Doesn't allocate reference types  


Que- 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 


Ans- New operator can't allocate functions but pointer to functions can be allocated  


Que- Which among the following is added in grammar of new operator? 

a. Finalize 

b. Arg 

c. Initializer 

d. Allocator 


Ans- Initializer  


Que- 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 


Ans- Can't be specified for arrays  


Que- 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 


Ans- Are not destroyed even if they go out of scope  


Que- 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 


Ans- Invokes function operator new  


Que- If 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 


Ans- Scope resolution  


Que- 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 


Ans- ::operator new( sizeof( type ) )  


Que- What is 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 


Ans- Deallocates a block of memory  


Que- 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 


Ans- It should be deleted using delete operator  


Que- Does delete return any value? 

a. Yes, positive value 

b. Yes, negative value 

c. Yes, zero value 

d. No 


Ans- No  


Que- Which type of value is resulted from the delete operator? 

a. void 

b. void pointer 

c. null pointer 

d. null 


Ans- void  


Que- 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 


Ans- Then unpredictable errors may arise  


Que- 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 


Ans- Can be used on pointer with value 0  


Que- 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 


Ans- Object destructor is called before deallocation  


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

d. 

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 


Ans- Its value is undefined  


Que- How many variants of delete operator are available? 

a. Only 1 

b. Only 2 

c. Only 3 

d. Only 4 


Ans- Only 2  


Que- Which is the correct syntax to delete a single object? 

a. delete *objectName; 

b. objectName delete; 

c. delete objectName; 

d. objectName *delete; 


Ans- delete objectName;  


Que- Which is the correct syntax to delete array of objects? 

a. delete [] objectName; 

b. delete * objectName; 

c. objectName[] delete; 

d. delete objectName[]; 


Ans- delete [] objectName;  


Que- 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 


Ans- delete [] on an object and delete on object array  


Que- 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 


Ans- Invokes function operator delete  


Que- 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 


Ans- Global delete operator is invoked  


Que- 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 


Ans- Can be defined for each class  


Que- What are automatic variables? 

a. Global variables 

b. Implicit/temporary variables 

c. Local variables 

d. System variables 


Ans- Local variables  


Que- 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 


Ans- Are allocated and deallocated automatically  


Que- 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 


Ans- Is actually function or block in which it is defined  


Que- 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 


Ans- Automatic variables are invisible to called function  


Que- 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 


Ans- The automatic variable doesn't get destroyed  


Que- Where are the automatic variables stored if another function is called in between the execution of program? 

a. Heap 

b. Queue 

c. Stack 

d. Temp variable 


Ans- Stack  


Que- 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 


Ans- Are not automatic variables  


Que- 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 


Ans- Are automatic by default  


Que- What values does uninitialized automatic variables contain? 

a. Null value 

b. Void value 

c. Undefined/Garbage 

d. Zero value 


Ans- Undefined/Garbage  


Que- 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 program 


Ans- When execution reaches the place of declaration of automatic variables  


Que- 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 


Ans- No, java supports local variable concept  


Que- 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 


Ans- Must be declared before using  


Que- Which error is produced if the automatic variables are used without declaration? 

a. Undefined symbol 

b. Memory error 

c. Type mismatch 

d. Statement missing 


Ans- Undefined symbol  


Que- In perl, using which operator are the local variables created? 

a. Dot 

b. Arrow 

c. Scope resolution 

d. my 


Ans- my  


Que- 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 


Ans- Instance variables are initialized implicitly while automatic are not  


Que- 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 


Ans- Variables to be used that are declared in another source file  


Que- 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 


Ans- Variable can be declared many times  


Que- 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 


Ans- Variable can be defined only once  


Que- 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 new program 

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

d. The source file doesn't matter for extern variables 


Ans- The source file must be included in the new file  


Que- 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 


Ans- Only declaration of variables  


Que- Which condition is true if 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 


Ans- Only one header file should declare it  


Que- 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 


Ans- function is extern by default  


Que- Which of the following results in allocation of memory for the extern variables? 

a. Declaration 

b. Definition 

c. Including file 

d. Memory is not allocated for extern variables 


Ans- Definition  


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


Ans- extern data_type variable_name;  


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


Ans- extern return_type function_name(argument_list);  


Que- 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 


Ans- The program can run successfully  


Que- 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 


Ans- There is no need to include any other header file for definition  


Que- 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 program 

d. Because those are visible throughout the program 


Ans- Because functions are always private  


Que- 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 


Ans- The predefined classes in a language  


Que- 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 


Ans- Must be included before use  


Que- What doesn't inbuilt classes contain? 

a. Function prototype 

b. Function declaration 

c. Function definitions 

d. Objects 


Ans- Function definitions  


Que- Which among the following not an inbuilt class in C++? 

a. System 

b. Color 

c. String 

d. Functions 


Ans- Functions  


Que- What is 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 


Ans- To handle all input streams  


Que- Which statement is true for 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 


Ans- Each class has an associated Array class  


Que- 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 


Ans- To use the mathematical functions  


Que- DataInputStream is derived from ______________________ 

a. StreamingInput 

b. StreamedInput 

c. StreameInput 

d. StreamInput 


Ans- StreamInput  


Que- 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 


Ans- Array_name.length  


Que- Number class can't manipulate ____________________ 

a. Integer values 

b. Float values 

c. Byte values 

d. Character values 


Ans- Character values  


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


Ans- exit(int);  


Que- Which class contain runFinalization() method? 

a. Finalize 

b. System 

c. Final 

d. SystemFinal 


Ans- System  


Que- 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 


Ans- Loads dynamic library for a path name  


Que- Which is not a System class variable? 

a. err 

b. out 

c. in 

d. put 


Ans- put  


Que- Which package contains the utility classes? 

a. jav

a.lang 

b. jav

a.utility 

c. jav

a.util 

d. jav

a.io 


Ans- jav

a.util  


Que- 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 


Ans- Object are immutable  


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


Ans- String object_Name = value;  


Que- 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 


Ans- Returns length of string excluding null character  


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


Ans- char charAt(index);  


Que- 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 


Ans- It returns the string from specified index till the end  


Que- 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 


Ans- String starting from first index and ending at second index position  


Que- 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 


Ans- Append one string at end of another string  


Que- 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 


Ans- Get the index of last occurrence of specified character in argument  


Que- 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 


Ans- Case sensitive, Case insensitive  


Que- 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 


Ans- Compare string object to another string object  


Que- 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 


Ans- Convert the whole string characters to uppercase  


Que- 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 


Ans- Remove white space from both the ends of string  


Que- Function replace() accepts _____________ arguments. 

a. 1 

b. 2 

c. 3 

d. 4 


Ans- 2  


Que- 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 


Ans- Second argument indicates the occurrence number of specified character from starting  


Que- 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 


Ans- To handle all the input and output operations  


Que- IO class provides input and output through ______________________ 

a. Data streams 

b. Serialization 

c. File system 

d. Data streams, serialization and file system 


Ans- Data streams, serialization and file system  


Que- Which among the following class contains the methods to access character based console device? 

a. Console 

b. File 

c. Device 

d. Pipe 


Ans- Console  


Que- 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 


Ans- An abstract which can be used to represent path names or file  


Que- 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 


Ans- A handle for machine specific structure of an open file  


Que- 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 


Ans- Gets the input stream from any open file only  


Que- What does FilePermission class do? 

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

b. This class is used to restrict use of permissions 

c. This class is used to represent device access permissions 

d. This class is used to represent file access permissions 


Ans- This class is used to represent file access permissions  


Que- Which class among the following makes incorrect assumptions? 

a. LineNumberInputStream 

b. LineNumberReader 

c. LineReader 

d. LineBuffer 


Ans- LineNumberInputStream  


Que- 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 


Ans- Abstract class to read character streams  


Que- Which class can handle IO class interrupt? 

a. ExceptionIO 

b. InteruptedIO 

c. InteruptedIOException 

d. IOInteruptException 


Ans- InteruptedIOException  


Que- 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 


Ans- A character stream whose source is String only  


Que- Which exception handler can be used when character encoding is not supported? 

a. UnsupportedException 

b. UnsupportedEncodingException 

c. SupportException 

d. EncodingException 


Ans- UnsupportedEncodingException  


Que- 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 


Ans- Read and write to a random access file  


Que- Which among the following is a serialization descriptor for any class? 

a. StreamClass 

b. ObjectStreamClass 

c. ObjectStream 

d. StreamObjectClass 


Ans- ObjectStreamClass  


Previous Post Next Post