Object Oriented MCQ Set 1
1) Which of the following property is associated with objects?
a) State
b) Behavior
c) Identity
d) All of the mentioned
Answer
Answer: d [Reason:] An object has state, exhibits some well defined behavior, and has a unique identity.
2) Which of the property of a object encompasses all of the (usually static) properties of the object plus the current (usually dynamic) values of each of these.
a) Semantics
b) Behavior
c) State
d) Identity
Answer
Answer: c [Reason:] None.
3) The following is an example of
Struct PersonnelRecord
{
char name[100];
int socialSecurityNumber;
char department[10];
float salary;
};
a) Objects
b) Class
c) Both a and b
d) None of the mentioned
Answer
Answer: b [Reason:] The above declaration denotes a class, not an object, because it does not represent a specific instance. To declare objects of this class we usually write in the following way:
PersonnelRecord deb, dave, jim, tom;
Class declaration is almost similar to struct declaration except that in reality it uses a keyword ‘class’ in place of ‘struct.’
4) Which of the following object types are generally autonomous, meaning that they can exhibit some behavior without being operated upon by another object
a) Passive
b) Active
c) Both a and b
d) None of the mentioned
Answer
Answer: b [Reason:] None.
5) A ________ is a description of a set of objects that share the same attributes, operations, relationships, and semantics.
a) Structure
b) Class
c) Constructor
d) Function
Answer
Answer: b [Reason:] Classes are the most important building blocks of any object- oriented systems. Classes are used to capture the vocabulary of the system you are developing. Modeling a system involves identifying the things that are important to your particular view. Hence all the above mentioned properties would distinguish each class from one another.
6) A ________ is a special member function whose task is to initialize the objects of its class.
a) Constructor
b) Destructor
c) Selector
d) Iterator
Answer
Answer: a [Reason:] Constructors are special because its name is same as the class name. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it constructs the value of data members of the class.
7) Which of the following statements about a constructor is not true?
a) We cannot refer to their addresses.
b) They cannot be inherited, though a derived class can call the base class constructor.
c) An object with a constructor can be used as a member of a union.
d) Constructors cannot be virtual.
Answer
Answer: c [Reason:] An object with a constructor cannot be used as a member of a union. A union is a limited form of the class type. It can contain access specifiers (public, protected, private), member data, and member functions, including constructors and destructors. It cannot contain virtual member functions or static data members. Default access of members in a union is public. A union cannot be used as a base class and cannot be derived from a base class. (same with the constructor too, constructor cannot be inherited, though a derived class can call the basic class constructor).
8) The constructors that can take arguments are called _____
a) Default Constructor
b) Copy Constructor
c) Parameterized Constructor
d) Dynamic Constructor
Answer
Answer: c [Reason:] In order to initialize the various data elements of different objects with different values when they are created parameterized constructors are used.
9) When an object is created and initialized at the same time, a ___ constructor gets called.
a) Inline Constructor
b) Copy Constructor
c) Default Constructor
d) Parameterized Constructor
Answer
Answer: b [Reason:] A copy constructor takes reference to an object of the same class as itself as an argument.
10) Destructor is defined as _______
a) Const matrix X(m, n);
b) matrix:: ~matrix(){ }
c) matrix:: matrix(void)
d) matrix()
Answer
Answer: b [Reason:] A destructor is used to destroy the objects that have been created by a constructor. Like a constructor, the destructor is a member function whose name is same as the class name but is preceded by a tilde.
Object Oriented MCQ Set 2
1. Which of the following data types are available in Java?
a) Primitive Datatypes
b) Reference Datatypes
c) Both
d) None of the mentioned
Answer
Answer: b [Reason:] Primitive Datatypes are defined by Java. Reference Datatypes are user defined, created using defined constructors of class.
2. How many Primitive data types are there in Java?
a) 4
b) 2
c) 8
d) 7
Answer
Answer: c [Reason:] Java defines eight simple types of data which are put in four groups. They are integers, floating-point numbers, boolean, characters.
3. Which of the following data types comes under ‘Integer’ data type?
a) short
b) long
c) int
d) all of the mentioned
Answer
Answer: d [Reason:] None.
4. Which of the following data types comes under ‘Floating’ data type?
a) float
b) byte
c) double
d) a and c
Answer
Answer: d [Reason:] Only ‘float’ and ‘double’ belong to floating-point numbers. ‘byte’ comes under ‘Integer’ data type.
5. Which of the following is not a primitive data type?
a) enum
b) short
c) byte
d) char
Answer
Answer: a [Reason:] An ‘enum’ data type is special data type that enables a variable to store set of predefined constants.
6. Which of following cannot be stored in character data type?
a) Special symbols
b) String
c) Letter
d) Digit
Answer
Answer: b [Reason:] String is a collection of characters and is stored in a variable of string data type.
7. Which of the following is smallest integer data type?
a) short
b) long
c) byte
d) double
Answer
Answer: c [Reason:] ‘byte’ is signed 8-bit smallest integer data type that has range from -128 to 127.
8. Which of the following keyword is used to declare Byte data type?
a) Bytes
b) Byte
c) bytes
d) byte
Answer
Answer: d [Reason:] None.
9. Which of the following data type is used to create a number for counting or indexing arrays?
a) byte
b) long
c) int
d) float
Answer
Answer: c [Reason:] None.
10. Which of the following data type stores longest floating-point value?
a) boolean
b) double
c) float
d) long
Answer
Answer: b [Reason:] ‘double’ is the longest data type with 64-bit defined by Java to store floating-point values.
Object Oriented MCQ Set 3
1. Which of the following data type is used to fetch stream of data from network or file?
a) char
b) int
c) byte
d) double
Answer
Answer: c [Reason:] when input is taken from keyboard or file it is taken in the form of bits by the machine. Byte is a collection of bits that makes user read a character at the output at a time. Usage of byte also saves memory.
2. What is the size(in bytes) of ‘byte’ primitive data type?
a) 4
b) 1
c) 2
d) 8
Answer
Answer: b [Reason:] ‘byte’ is a signed 8-bit(1byte) data type defined by Java.
3. What is the minimum value of ‘short’ data type?
a) -32,768
b) -127
c) -2,147,483,648
d) -32,767
Answer
Answer: a [Reason:] None.
4. What is the maximum value of ‘byte’ data type?
a) 2^7
b) 2^7+1
c) 2^7-1
d) None of the mentioned
Answer
Answer: c [Reason:] None.
5. What is the range of ‘short’ data type?
a) -(2^15+1) to (2^15-1)
b) -2^15 to 2^15
c) -(2^15-1) to (2^15+1)
d) -(2^15-1) to 2^15
Answer
Answer: d [Reason:] None.
6. Which of the following is default value of ‘int’ data type?
a) 0
b) null
c) true
d) false
Answer
Answer: a [Reason:] Default value is assigned to a variable by memory when it is declared but not initialized.
7. Which of the following is default value of ‘double’ data type?
a) 0
b) 0.0d
c) null
d) false
Answer
Answer: b [Reason:] Default value is assigned to a variable by memory when it is declared but not initialized.
8. What is the range of ‘byte’ data type?
a) -127 to 127
b) -128 to 127
c) -127 to 128
d) -128 to 127
Answer
Answer: d [Reason:] None.
9. What is the output of the program?
-
class Test
-
{
-
public static void main(String args[])
-
{
-
int a = 12;
-
int b = 0;
-
int c = a/b;
-
System.out.println("The value of c is"+c);
-
}
-
}
a) Compilation error
b) Run time error
c) The value of c is 0
d) None of the mentioned
Answer
Answer: b [Reason:] The above code results in Exception in thread main.Division by zero is not defined in Java.
10. Which of the following is not considered as data type in Java?
a) String
b) int
c) boolean
d) double
Answer
Answer: a [Reason:] None.
Object Oriented MCQ Set 4
1. Which of these is a valid keyword in Java?
a) interface
b) string
c) float
d) unsigned
Answer
Answer: a [Reason:] “String” and “Float” are class types in Java. “unsigned” is a keyword used in C/C++ but not in Java.
2. Which of these is a reserved word in Java Programming Language?
a) method
b) native
c) subclasses
d) reference
Answer
Answer: b [Reason:] “native” is a valid keyword used to modify method declaration. The valid keyword used in Java language for subclassing is “extends” not subclasses.
3. How many reserved keywords are there in Java language?
a) 50
b) 52
c) 49
d) 45
Answer
Answer: a [Reason:] As of Java 1.5 there are 50 keywords out of which 48 are used(const and goto keywords are unusable keywords).
4. Which of the following is a Literal Representation?
a) 100
b) ‘100’
c) Sample
d) None of the mentioned
Answer
Answer: a [Reason:] A constant value in Java is created by using a ‘Literal Representation’ of it. Integer Literals are not enclosed in quotes where as String Literals are enclosed in quotes.
5. What are the types of comments defined by Java?
a) Single-line comment
b) Multi-line comment
c) Documentation comment
d) All of the mentioned
Answer
Answer: d [Reason:] None.
6. Which of the following is readable by both Computer and Human?
a) Single-line comment
b) Multi-line comment
c) Documentation comment
d) All of the mentioned
Answer
Answer: c [Reason:] Documentation comment is used to produce an HTML file that documents the given program.
7. Which of the following ‘Seperator’ is most commonly used in Java program?
a) Parenthesis
b) Braces
c) Comma
d) Semicolon
Answer
Answer: d [Reason:] Semicolon is most commonly used in Java program, which terminates statements.
8. Which of the following is used to name class, method and variables?
a) Identifiers
b) Keywords
c) Both
d) None of the mentioned
Answer
Answer: a [Reason:] Identifiers are used to name classes, methods and variables.
9. ‘Whitespace’ in Java language may be?
a) A space
b) A new line
c) A tab
d) All of the mentioned
Answer
Answer: d [Reason:] None.
10. Which of the following is the output of the program?
-
class Test {
-
public static void main(String args[])
-
{
-
int num = 10;
-
System.out.println("The value of num is" +NUM);
-
}
-
}
a) Compilation error
b) Run time error
c) Exception
d) The value of num is 10
Answer
Answer: a [Reason:] Java is case-sensitive. Identifier which is used to name variable and print are different.