Object Oriented MCQ Number 01258

Object Oriented MCQ Set 1

1) The method of design encompassing the process of object oriented decomposition and a notation for depicting both logical and physical and as well as static and dynamic models of the system under design is known as:
a) Object- Oriented Programming
b) Object- Oriented Design
c) Object- Oriented Analysis
d) None of the mentioned

Answer

Answer: b [Reason:] The definition has two important parts. The former part uses the class and object abstractions to logically structure systems, and the latter uses algorithmic abstractions. The term object oriented design (OOD) is used to refer any method that leads to object oriented decomposition.

2) What is the programming style of the object oriented conceptual model?
a) Invariant relationships
b) Algorithms
c) Classes and objects
d) Goals, often expressed in a predicate calculus.

Answer

Answer: c [Reason:] Object oriented programming follows a conceptual framework called object model and is implemented by writing classes and objects to make its style clear unlike procedure- oriented language.

3) The essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer is called:
a) Encapsulation
b) Modularity
c) Hierarchy
d) Abstraction

Answer

Answer: d [Reason:] Abstraction focuses only on the outside view of an object and separates object’s essential behavior from its implementation. It explains what an object does but doesn’t explain how it does.

4) Abstraction is classified into _______ types
a) 4
b) 3
c) 2
d) 1

Answer

Answer: a [Reason:] Entity abstraction, Action abstraction, Virtual machine abstraction, Coincidental abstraction

5) The process of compartmentalizing the elements of an abstraction that constitute its structure and behavior is called as
a) Hierarchy
b) Encapsulation
c) Modularity
d) Entity Abstraction

Answer

Answer: b [Reason:] Encapsulation focuses upon the implementation that gives rise to this behavior and is mostly often achieved through information hiding i.e., abstraction.

6) Single inheritance, Multiple inheritance, and Aggregation comes under _______
a) Modularity
b) Typing
c) Hierarchy
d) None of the mentioned

Answer

Answer: c [Reason:] All the three types are the examples of Hierarchy, as it denotes ranking or ordering of abstractions.

7) In which of the following mechanisms, types of all variables and expressions are fixed at compilation time.
a) Strong Typing
b) Weak Typing
c) Static Binding/ early binding
d) Dynamic Binding/ late binding

Answer

Answer: c [Reason:] The memory address of a variable can be statically bound to the variable at compile time or dynamically at runtime. Likewise, variables in some languages have dynamic types that change during program execution, while other variables have static types that remain fixed over the execution of the program. Only the binding of the value determines whether the object is a variable or something else (such as constant).

8) In which of the following mechanisms, types of all variables and expressions are not known until runtime
a) Strong Typing
b) Weak Typing
c) Static Binding/ early binding
d) Dynamic Binding/ late binding

Answer

Answer: d [Reason:] The memory address of a variable can be statically bound to the variable at compile time or dynamically at runtime. Likewise, variables in some languages have dynamic types that change during program execution, while other variables have static types that remain fixed over the execution of the program. Only the binding of the value determines whether the object is a variable or something else (such as constant).

9) Which of the following statements about Persistence is correct?
a) It is the enforcement of the class of an object, such that objects of different types may not be interchanged, or at the most they may be interchanged only in very restricted ways.
b) It is the property of an object through which its existence transcends time and/or space.
c) It is the property that distinguishes an active object from one that is not active.
d) All of the mentioned

Answer

Answer: b [Reason:] Persistence deals with lifetime of data. Persistence saves the state and class of an object across time or space.

10) What is that concept in type theory in which a single name may denote objects of many different classes that are related by some common super class referred to ______
a) Monomorphism
b) Type Checking
c) Polymorphism
d) Generalization

Answer

Answer: c [Reason:] Polymorphism is a feature of object oriented programming that usually takes the ability of creating an object, or variable, or a function in more than one form. Polymorphism exists when the features of inheritance and dynamic binding interact.

Object Oriented MCQ Set 2

1) Object oriented technology is built upon a sound engineering foundation, whose elements are collectively called as ___
a) Von Neumann Model
b) Object Model
c) Structured Model
d) Programming Model

Answer

Answer: b [Reason:] The object mode encompasses the principles of abstraction, encapsulation, modularity, typing, concurrency, and persistence which are the principles of object oriented programming language.

2) Which of the following programming language are object oriented in nature
a) Smalltalk and Simula
b) FORTRAN and ALGOL
c) C and Ada
d) Perl and Python

Answer

Answer: a [Reason:] In Smalltalk and Simula, data and methods of manipulating the data are kept as a single unit called an object.

3) Callback is an operation provided by
a) Inheritance
b) Encapsulation
c) Modularity
d) Abstraction

Answer

Answer: d [Reason:] A call back is a programming idiom which a client provides a function to the server and the server calls the client’s function whenever the appropriate conditions are met.

4) :reader, :writer or :accessor are the slot options in
a) Smalltalk
b) LISP
c) Object Pascal
d) CLOS

Answer

Answer: CLOS [Reason:] These are the options which grant a client read access, write access, or read/write access respectively.

5) Dependencies among files can then be asserted using the macro
a) #define
b) #undef
c) #include
d) #endif

Answer

Answer: c [Reason:] Modular implementations are placed in file named with a .c sufficx which are called header files. #include is necessary to tell the preprocessor where to look for header files if they are not placed in the current directory.

6) Inheritance is an example of which type of hierarchy
a) Class Structure
b) Object Structure
c) Both
d) None of the mentioned

Answer

Answer: a [Reason:] Inheritance is the most important “is a” (class structure) hierarchy and not “part of” (object structure) hierarchy.

7) Superclass represents ________ abstractions
a) Generalized abstractions
b) Specialization abstractions
c) Both
d) None of the mentioned

Answer

Answer: a [Reason:] Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass.

8) Subclass represents ___ abstractions
a) Generalized abstractions
b) Specialization abstractions
c) Both
d) None of the mentioned

Answer

Answer: b [Reason:] Specialization means creating new subclasses from an existing class.

9) _______ is the property that distinguishes an active object from one that is not active.
a) Persistence
b) Typing
c) Aggregation
d) Concurrency

Answer

Answer: d [Reason:] None.

10) Which of the following statements about object model is true?
I. Object model encourages the reuse of software and entire design of the application.
II. Object model produces systems that are built upon stable intermediate forms.
III. Object model reduce the inherent in developing complex systems.
IV. None of the mentioned
a) I, III
b) I, II
c) I, II, III
d) IV

Answer

Answer: c [Reason:] All the above written statements are the benefits of object model.

Object Oriented MCQ Set 3

1. Which of the following approach help us understand better about Real time examples, say Vehicle or Employee of an Organisation?
a) Procedural approach
b) Object Oriented approach
c) Both a and b
d) None of the mentioned

Answer

Answer: b [Reason:] Object Oriented Programming supports the concept of class and object which help us understand the real time examples better. Vehicle is defined to be a class. Car, truck, bike are defined to be objects of the class, Vehicle.

2. Which of the following Paradigm is followed by Object Oriented Language Design?
a) Process-Oriented Model
b) Data Controlling access to code.
c) Both a and b
d) None of the mentioned

Answer

Answer: b [Reason:] Object-oriented programming organises a program around its data(that is, objects) and a set of well-defined interfaces to that data.

3. Which of the following approach is followed by Object Oriented Language during the execution of a program?
a) Bottom up approach
b) Top down approach
c) Both a and b
d) None of the mentioned

Answer

Answer: a [Reason:] Bottom up approach begins with details and moves to higher conceptual level there by reducing complexity and making the concept easier to understand.

4. Which of the following is/are advantage of using object oriented programming?
a) Code Reusability
b) Can create more than one instance of a class without interference
c) Platform independent
d) All of the mentioned

Answer

Answer: d [Reason:] None.

5. Java Compiler translates the source code into?
a) Machine code
b) Assembly code
c) Byte code
d) JVM code

Answer

Answer: c [Reason:] Java program is converted into ‘byte code’ which makes it easier to run on wide variety of environments. Only the run-time package JVM has to be implemented for each platform.

6. What is the output of this program?

  1. class PrintTest {
  2.     public static void main(String args[])
  3.     {
  4.         int num = 10;
  5.         if (NUM < 100) {
  6.             System.out.println("The value of num is"+ num);
  7.         }
  8.     }
  9. }

a) Compilation error
b) Run time error
c) The value of num is 10
d) None of the mentioned

Answer

Answer: a [Reason:] Java is case-sensitive. The variable ‘num’ used in print statement is not same as the variable ‘NUM’ used in the if conditional statement.

7. Which of the following is called as ‘Comiplation unit’?
a) Object file
b) Byte code
c) Source file
d) All of the mentioned

Answer

Answer: c [Reason:] None.

8. What is the output of this program?

  1. class TypeChecking {
  2.     public static void main(String args[]) 
  3.     {
  4.         int num = 10.5;
  5.         System.out.println("Output :The value of num is" +num);
  6.     }
  7. }

a) Output: The value of num is 10.5
b) Run-time error
c) Compilation error
d) None of the mentioned

Answer

Answer: c [Reason:] Java is storngly typed language. The variable num is declared as ‘int’ but the value assigned to it is ‘float’, as a result the code does not get compiled.

9. Which is a named memory location assigned a value by the program?
a) variable
b) literal
c) identifier
d) None of the mentioned

Answer

Answer: a [Reason:] None.

10. What is the output of this program?

  1.  class A {
  2.      int i, j;
  3.      void showij() {
  4.          System.out.println("i and j:" + i +" "+j);
  5.      }
  6.  }
  7.  class B extends A
  8.  {
  9.      int k;
  10.      void showk()
  11.      {
  12.          System.out.println("k: "+ k);
  13.      }
  14.      void sum() {
  15.          System.out.println("i + j + k:" + (i + j + k));
  16.      }
  17.  }  
  18.  class SimpleInheritance {
  19.      public static void main(String args[]) 
  20.      {     
  21.          B subob = new B();
  22.          subob.i = 5;
  23.          subob.j = 6;
  24.          subob.k = 9;
  25.          System.out.println("The contents are");
  26.          subob.showk();
  27.          subob.sum();
  28.       }
  29.  }

a) Run-time error
b) Compilation error
c) Output: The contents are k: 9
d) None of the mentioned

Answer

Answer: c [Reason:] class B inherits from class A and can access the variables i and j through class A.

Object Oriented MCQ Set 4

1. Which of the following is the functionality of ‘Data Abstraction’?
a) Reduce Complexity
b) Binds together code and data
c) Parallelism
d) None of the mentioned

Answer

Answer: a [Reason:] An essential element of Object Oriented Programming is ‘Data Abstraction’ which means hiding things. Complexity is managed through abstraction.

2. Which of the following mechanisms is/are provided by Object Oriented Language to implement Object Oriented Model?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) All of the mentioned

Answer

Answer: d [Reason:] None.

3. Which of the these is the functionality of ‘Encapsulation’?
a) Binds together code and data
b) Using single interface for general class of actions.
c) Reduce Complexity
d) All of the mentioned

Answer

Answer: a [Reason:] ‘Encapsulation’ acts as protective wrapper that prevents code and data from being accessed by other code defined outside the wrapper.

4. What is ‘Basis of Encapsulation’?
a) object
b) class
c) method
d) all of the mentioned

Answer

Answer: d [Reason:] Encapsulation is the mechanism that binds together code and data it manipulates, and keeps both safe from outside interface and misuse. Class, which contains data members and methods is used to implement Encapsulation.

5. How will a class protect the code inside it?
a) Using Access specifiers
b) Abstraction
c) Use of Inheritance
d) All of the mentioned

Answer

Answer: a [Reason:] Each method or variable in a class may be marked ‘public’ or ‘private’. They are called Access Specifiers.

6. What is the output of this program?

  1.  class Test {
  2.      int a;
  3.      public int b;
  4.      private int c;
  5.  }
  6.  class AcessTest {
  7.      public static void main(String args[])
  8.      {
  9.          Test ob = new Test();
  10.          ob.a = 10;
  11.          ob.b = 20;
  12.          ob.c = 30;
  13.          System.out.println(" Output :a, b, and c" + ob.a + " " + ob.b + " " + ob.c);
  14.      }
  15. }

a) Compilation error
b) Run time error
c) Output : a, b and c 10 20 30
d) None of the mentioned

Answer

Answer: a [Reason:] Private members of a class cannot be accessed directly. In the above program, the variable c is a private member of class ‘Test’ and can only be accessed through its methods.

7. Which of the following is a mechanism by which object acquires the properties of another object?
a) Encapsulation
b) Abstraction
c) Inheritance
d) Polymorphism

Answer

Answer: c [Reason:] ‘Inheritance’ is the mechanism provided by Object Oriented Language, which helps an object to acquire the properties of another object usually child object from parent object.

8. Which of the following supports the concept of hierarchical classification?
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance

Answer

Answer: d [Reason:] Use of Hierarchical classification avoids defining the properities of object explicitly at each level which have acquired their properties from higher levels.

9. Which Keyword from the following is used to inherit properties from one class into another?
a) extends
b) subclasses
c) native
d) all of the mentioned

Answer

Answer: a [Reason:] None.

10. Which of the following concept is often expressed by the phrase, ‘One interface, multiple methods’?
a) Abstraction
b) Polymorphism
c) Inheritance
d) Encapsulation

Answer

Answer: b [Reason:] None.

Object Oriented MCQ Set 5

1. In how many ways can an object be passed to a function?
a) 1
b) 2
c) 3
d) 4

Answer

Answer: c [Reason:] The objects can be passed in three ways. Pass by value, pass by reference and pass by address. These are the general ways to pass the objects to a function.

2. If an object is passed by value, ____
a) A new copy of object is created implicitly
b) The object itself is used
c) Address of the object is passed
d) A new object is created with new random values

Answer

Answer: a [Reason:] When an object is passed by value, a new object is created implicitly. This new object uses the implicit values assignment, same as that of the object being passed.

3. Pass by address passes the address of object ___ and pass by reference passes the address of the object ___
a) Explicitly, explicitly
b) Implicitly, implicitly
c) Explicitly, Implicitly
d) Implicitly, explicitly

Answer

Answer: c [Reason:] Pass by address uses the explicit address passing to the function whereas pass by reference implicitly passes the address of the object.

4. If an object is passed by reference, the changes made in the function _____
a) Are reflected to the main object of caller function too
b) Are reflected only in local scope of the called function
c) Are reflected to the copy of the object that is made during pass
d) Are reflected to caller function’s object and called function object also

Answer

Answer: a [Reason:] When an object is passed by reference, its address is passed implicitly. This will make changes to the main function whenever any modification is done.

5. Constructor function is not called when an object is passed to a function, will its destructor be called when its copy is destroyed?
a) Yes, depending on code
b) Yes, must be called
c) No, since no constructor was called
d) No, since same object gets used

Answer

Answer: b [Reason:] Even though the constructor is not called when the object is passed to a function, the copy of the object is still created, where the values of the members are same. When the object have to be destroyed, the destructor is called to free the memory and resources that the object might have reserved.

6. When an object is returned by a function, a ___ is automatically created to hold the return value.
a) Temporary object
b) Virtual object
c) New object
d) Data member

Answer

Answer: a [Reason:] The temporary object is created. It holds the return value. The values gets assigned as required, and the temporary object gets destroyed.

7. Is the destruction of temporary object safe (while returning object)?
a) Yes, the resources get free to use
b) Yes, other objects can use the memory space
c) No, unexpected side effects may occur
d) No, always gives rise to exceptions

Answer

Answer: c [Reason:] The destruction of temporary variable may give rise to unexpected logical errors. Consider the destructor which may free the dynamically allocated memory. But this may abort the program if another is still trying to copy the values from that dynamic memory.

8. How to overcome the problem arising due to destruction of temporary object?
a) Overloading insertion operator
b) Overriding functions can be used
c) Overloading parenthesis or returning object
d) Overloading assignment operator and defining copy constructor

Answer

Answer: d [Reason:] The problem can be solved by overloading the assignment operator to get the values that might be getting returned while the destructor free the dynamic memory. Defining copy constructor can help us to do this in even simpler way.

9. How many objects can be returned at once?
a) Only 1
b) Only 2
c) Only 16
d) As many as required

Answer

Answer: a [Reason:] Like any other value, only one object can be returned at ones. The only possible way to return more than one object is to return address of an object array. But that again comes under returning object pointer.

10. What will be the output of the following code?

Class A
{ 
int i; 
public : A(int n)
{ 
		i=n; cout&lt;&lt;”inside constructor ”;
} 
	~A()
{
cout&lt;&lt;”destroying  ”&lt;&lt;i;
}
void seti(int n)
{
		i=n;
}
int geti()
{
return I;
}
};
void t(A ob)
{ 
cout&lt;&lt;”something ”;
}
int main()
{
	A a(1);
	t(a);
cout&lt;&lt;this is i in main ”;
cout&lt;&lt;a.geti();
}

a) inside constructor something destroying 2this is i in main destroying 1
b) inside constructor something this is i in main destroying 1
c) inside constructor something destroying 2this is i in main
d) something destroying 2this is i in main destroying 1

Answer

Answer: a [Reason:] Although the object constructor is called only ones, the destructor will be called twice, because of destroying the copy of the object that is temporarily created. This is the concept of how the object should be passed and manipulated.

11. It is necessary to return the object if it was passed by reference to a function.
a) Yes, since the object must be same in caller function
b) Yes, since the caller function needs to reflect the changes
c) No, the changes are made automatically
d) No, the changes are made explicitly

Answer

Answer: c [Reason:] Having the address being passed to the function, the changes are automatically made to the main function. In all the cases if the address is being used, the same memory location will be updated with new values.

12. How many objects can be passed to a function simultaneously?
a) Only 1
b) Only an array
c) Only 1 or an array
d) As many as required

Answer

Answer: d [Reason:] There is no limit to how many objects can be passed. This works in same way as that any other variable gets passed. Array and object can be passed at same time also.

13. If an object is passed by address, will be constructor be called?
a) Yes, to allocate the memory
b) Yes, to initialize the members
c) No, values are copied
d) No, temporary object is created

Answer

Answer: c [Reason:] A copy of all the values is created. If the constructor is called, there will be a compile time error or memory shortage. This happens because each time a constructor is called, it try to call itself again and that goes infinite times.

14. Is it possible that an object of is passed to a function, and the function also have an object of same name?
a) No, Duplicate declaration is not allowed
b) No, 2 objects will be created
c) Yes, Scopes are different
d) Yes, life span is different

Answer

Answer: a [Reason:] There can’t be more than one variable or object with the same name in same scope. The scope is same, since the object is passed, it becomes local to function and hence function can’t have one more object of same name.

15. Passing an object using copy constructor and pass by value are same.
a) True
b) False

Answer

Answer: b [Reason:] The copy constructor is used to copy the values from one object to other. Pass by values is not same as copy constructor method. Actually the pass by value method uses a copy constructor to copy the values in a local object.

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.