Monday, February 28, 2011

MCQ: OOP's

What is an Object?
A. A combination of message and data 
B. A combination of namespace
C. A combination of task to be performed
D. A combination of Array
ANSWER: A

What is an Encapsulation?
A. An action or occurrence such as click
B. A package of one or more components together 
C. A set of statement that performs specific task
D. A reference type variable
ANSWER: B

Which of the following is example of encapsulation
A. Steering wheel of the car
B. Car
C. Color of the car
D. Music system of the car
ANSWER: B

Which of the following are not in composition in " Car as a system"
A. Car and seat covers
B. Car and music system
C. Car and color
D. Car and engine
ANSWER: B

Which of the following are in aggregation in "Mobile as a system"
A. Operating system in mobile
B. Charger of mobile
C. Extenal apps installed in mobile
D. None
ANSWER: B

Which one is not the property related to " Car as an object"
A. Color
B. Max Speed
C. Petrol/Disel capacity
D. All
ANSWER: D

Is eye color property of human being?
A. True
B. False
ANSWER: A

States and districts have a:
A. Bi-directional realtion
B. Uni-Directional relation
C. Its not a relation
D. None
ANSWER: A

Choose one of the following
A. Struct is encapsulation
B. Class is encapsulation
C. Functions is encapsulation
D. Both A&B
ANSWER: D

What is a class?
A. An abstract representation of something with certain properties .
B. A concrete  representation of something with certain properties .
C. An abstract representation of something with certain properties and abilities.
D. A concrete representation of something with certain properties and abilities.
ANSWER: C


Polymorphism reduces the effort required to extend an object system by
A. Coupling objects together more tightly
B. Enabling a number of different operations to share the same name
C. Making objects more dependent on one another
D. Removing the barriers imposed by encapsulation.
ANSWER: B


Which  is analogous to the floor plan of a house?
A. Architectural design
B. Component-level design
C. Data design
D. Interface design
ANSWER: A

Which is analogous to the detailed drawings of the access points and external utilities for a house?
A. Architectural design
B. Component-level design
C. Data design
D. Interface design
ANSWER: D

Which  is analogous to a set of detailed drawings for each room in a house
A. Architectural design
B. Component-level design
C. Data design
D. Interface design
ANSWER: B

What is the default access specifier for a Top-level Class, which are not nested into other Classes?
A. Public
B. Private
C. Protected
D. Internal
ANSWER: D

Can overloaded methods be override too?
A. true
B. false
ANSWER: A

Can we override the main method?
A. True
B. False
ANSWER: B

Can we create an object for an interface?
A. True
B. False
ANSWER: A

What is the difference between Assignment and Initialization?
A.  Assignment can be done as many times as desired whereas initialization can be done only once.
B. Assignment can be done only once whereas initialization can be done as many times as desired.
C. Both are same
D. None of the above
ANSWER : A


What modifiers may be used with top-level class?
A. public
B. abstract and final
C. Both A & B
D. Only B
ANSWER : C


What is inner class ?
A. Classes defined in other classes
B. Classes defined in methods
C. Both A & B
D. Only A
ANSWER : C


What is anonymous class?
A. Class defined inside a method without a name
B. It is instantiated and declared in the same place and cannot have explicit constructors
C. Both A & B
D. Only A
ANSWER : C


Anonymous classes cannot have explicit constructors.
A. True
B. False
ANSWER : A


An inner class can be private.
A. True
B. False
ANSWER : A


What are the different creational patterns in OO design?
A. Factory pattern & Single ton pattern
B. Prototype pattern & Abstract factory pattern
C. Both A & B
D. Only A
ANSWER : C


A method will affect only a particular object to which it is specified.
A. True
B. False
ANSWER : A


What are the advantages of inheritance? 
A. It permits code reusability. Reusability saves time in program development.
B. It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.
C. Both A & B
D. Only A
ANSWER : C


The relationship between a teacher & a student is
A. Association
B. Aggregation
C. Composition
D. None of these
ANSWER : A


The relationship between a teacher & a department is
A. Association
B. Aggregation
C. Composition
D. None of these
ANSWER : B


The relationship between a house & room is
A. Association
B. Aggregation
C. Composition
D. None of these
ANSWER : C


What is the difference between virtual functions and pure virtual functions?
A. A virtual function must have a definition in the class in which it is declared. A pure virtual function does not provide a definition.
B. A virtual function does not provide a definition. A pure virtual function must have a definition in the class in which it is declared.
C. Both are same.
D. None of these.
ANSWER : A


What is the difference between the terms fatal error and non–fatal error?
A. A fatal error causes a program to terminate prematurely. A nonfatal error occurs when the logic of the program is incorrect, and the program does not work properly.
B. A fatal error immediately lets you know there is a problem with the program, whereas a nonfatal error can be subtle and possibly go undetected.
C. Both A & B
D. Only A
ANSWER : C


 Polymorphism enables you to program “in the specific” rather than “in the general.”
A. True
B. False
ANSWER : B

The return data type of void means? 
A. A void area in memory is returned so that you can populate it.
B. No data type is returned.
C. void is not a valid data type.
D. None of the above
ANSWER : B

When working with Primitive Data, you can assign a lower precision to a higher precision because C# will implicitly cast.
A. True
B. False
ANSWER : A

Which statements about the C# language are true? 
A. C# supports both procedural and object-oriented programming
B. C# is only a procedural language.
C. C# is only an Object-Oriented.
D. None of the above.
ANSWER : A

Which statements are not correct about Objects? 
A. An Object is an instance of a class
B. Objects can access both instance and static data
C. All classes extend the Object class
D. Objects do not permit encapsulation
ANSWER : D

If an attribute is private, which methods have access to it?
A. Only those defined in the same class.
B. Only static methods in the same class.
C. Only instance methods in the same class.
D. Only classes in the same package.
ANSWER : A

What is an aggregate object?
A. An object instance that has only static methods.
B. An object instance that has only primitive attributes.
C. An object instance that contains other objects.
D. An object that has only primitive attributes and instances methods.
ANSWER : C

Which definition best describes the concept of polymorphism?
A. Polymorphism is the technique by which an object that is used to invoke a method can actually invoke different methods, depending on the nature of the control structure.
B. Polymorphism is the technique by which an object is used to invoke overridden methods at different times, depending on the nature of the application.
C. Polymorphism is the technique by which an object reference is used to refer to any object created from a class that is related to the reference type by inheritance.
D. Polymorphism is the technique by which an object’s parameters are used to instantiate a particular type, depending on the nature of the parameters.
ANSWER : C

Inheritance is the act of deriving a new class from an existing one.
A. True
B. False
ANSWER : A

A class can have many methods with the same name, as long as the number of parameters is different.  This is known as: 
A. Method Overloading
B. Method Invocating
C. Method Overriding
D. Method Labeling
ANSWER : A

 ___________ is a blueprint or prototype that defines the variables and the methods common to all objects of a certain kind.  Select the best word to complete this sentence.
A. Class
B. Inheritance
C. Polymorphism
D. Aggregation
ANSWER : A

(A/An) ____________ is a contract in the form of a collection of method and constant declarations. When a class implements (a/an) ____________, it promises to implement all of the methods declared in that ____________.  Select the best word to complete this sentence.
A. Class
B. Interface
C. Object
D. Exception
ANSWER : B

The phrase “is a” refers to the object-oriented concept of ____________, and the phrase “has a” refers to the object-oriented concept of ____________.
A. Composition : Inheritance
B. Composition : Polymorphism
C. Polymorphism : Inheritance
D. Inheritance : Composition
ANSWER : D

UML stands for which of the following?
A. Unified Modeling Language
B. Universal Modeling Language
C. Unified Modelers Language
D. Unary Model Language
ANSWER : A

If objects are encapsulated, the rest of the system interacts with an object only through a well-defined set of services. 
A. True
B. False
ANSWER : A

When using method overriding, which of the following is true?
A. The number of parameters determines which version of an overridden method is invoked.
B. The class determines which version of an overridden method is invoked.
C. The method signature determines which version of an overridden method is invoked.
D. The object reference determines which version of an overridden method is invoked.
ANSWER : B

Analyze the following method signature and select the statement that must be true: private int someMethod(int a, Object b, String c, char d)
A. a is pass by reference, b is pass by value, c is pass by reference, and d is pass by value
B. a is pass by value, b is pass by reference, c is pass by reference, and d is pass by value
C. a is pass by reference, b is pass by reference, c is pass by reference, and d is pass by reference
D. a is pass by reference, b is pass by value, c is pass by value, and d is pass by value
ANSWER : B

Object Oriented Programming
A. makes programs more reliable.
B. simulates real life.
C. uses a lot of intimidating vocabulary, which is not as bad as it sounds.
D. is all of the above.
ANSWER: B

The actions in a C# class are called
A. procedures.
B. functions.
C. methods.
D. subroutines.
ANSWER: C

Which of the following Math class features do not use as any parameters or arguments?
A. PI
B. E
C. final
D. Both A and B
ANSWER: C

What is the value of result in the following statement? int result = Math.pow(3,4);
A. 12
B. 81
C. 64
D. None
ANSWER: D

A conditional statement is
A. a program expression that evaluates to true or false.
B. a program statement that requires input from the keyboard.
C. any program statement with a binary operator.
D. any program statement with an unary operator.
ANSWER: A

A class method call
A. requires that the class identifier precedes the method identifier.
B. may be called with the method identifier only in certain circumstances.
C. is only possible after a new object is constructed.
D. uses the class identifier only for readability.
ANSWER: B

Class methods are typically used when
A. only a single copy of the class needs to be loaded
B. multiple copies or instances of a class are required.
C. it is not necessary to pass information to the methods.
D. only return methods are used in a class.
ANSWER: B

Object methods are typically used when
A. only a single copy of the class needs to be loaded
B. multiple copies or instances of a class are required.
C. it is not necessary to pass information to the methods.
D. only return methods are used in a class.
ANSWER: A

Which of the following statements shows correct syntax to create an object of the Piggy class?
A. Piggy new tom = Piggy();
B. Piggy = new tom();
C. Piggy tom = new Piggy();
D. tom = new Piggy;
ANSWER: C

The Boolean expression (A && B) && !(A && B) evaluates to
A. false in all cases.
B. true in all cases.
C. true whenever only A is true or only B is true.
D. true whenever both A is true and B is true.
ANSWER : A


The do..while loop is ideal for loop structures that
A. repeat some process a fixed number of times.
B. must execute some process at least one time.
C. must check the loop condition before the loop body is executed.
D. do all of the above.
ANSWER : B

An array is a
A. data structure with one, or more, elements of the same type.
B. data structure with LIFO access.
C. data structure, which allows transfer between internal and external storage.
D. data structure with one, or more, elements, called fields, of the same or different data types.
ANSWER : A


A class
A. is a user-defined data type.
B. combines both data and the methods that act upon the data in the same module.
C. is one instance of a more general data type.
D. is both A and B.
ANSWER : D


An object
A. is a user-defined data type.
B. combines both data and the methods that act upon the data.
C. is one instance of a more general data type.
D. is both A and B.
ANSWER : C


The data in a class are also called
A. attributes.
B. instance variables.
C. fields.
D. all of the above.
ANSWER : C


Methods are
A. action modules that process data.
B. class variables that store information.
C. instances of a class.
D. none of the above.
ANSWER : A


Instantiation is the moment that
A. memory is allocated for a specific object of a class.
B. memory is allocated for a specific object, which is a member of a class.
C. a program is ready for execution.
D. a program compiles correctly.
ANSWER : A


Object Oriented Programming is characterized by using
A. encapsulation.
B. inheritance.
C. polymorphism.
D. all of the above.
ANSWER : D


The scope of an object is the
A. size of the memory allocated for an object.
B. total number of data attributes used by an object.
C. range of accessing member methods.
D. period during which an object is defined and allocates memory to store values.
ANSWER : C


When simple data types are used for parameter passing,
A. the actual current value of the simple data type's variable is copied.
B. the initial value of the simple data type's variable is copied.
C. the memory reference where the variable values are stored is copied.
D. a new object of the data type is instantiated.
ANSWER : A


When objects are used for parameter passing,
A. the current values of the data attributes of the object are copied.
B. the initial values of the object instantiation information are copied.
C. the memory reference where the object information is stored is copied.
D. a new object of the same class as the parameter object is instantiated.
ANSWER : A


Information hiding is the concept of
A. declaring all significant data as private.
B. storing information in private data fields.
C. thinking about programming features without concern about the implementation of these features.
D. testing a program without using any actual data.
ANSWER : B

When is a constructor called?
A. Each time the constructor identifier is used in a program statement
B. During the declaration of a new object
C. During the instantiation of a class
D. At the beginning of any program execution
ANSWER: C

What is an overloaded constructor?
A. A constructor with too many program statements.
B. A second constructor with the same constructor heading as the first constructor.
C. A second constructor with a different identifier than the first constructor.
D. A second or other multiple constructor with a different signature than any other constructor.
ANSWER: D

Access to private data or private methods is
A. restricted to methods of the same class.
B. restricted to methods of other classes.
C. available to methods of the same class and other classes.
D. not an issue because the program will not compile.
ANSWER: B

Inheritance is the process of
A. using classes in the established standard C# Language library.
B. using features from an existing class.
C. combining data and the methods, which process the data, inside the same module.
D. dividing a program into multiple related files for each class in the program.
ANSWER: B

If a subclass has the same method identifier as a baseclass method,
A. a compile error message will result.
B. a logic error will result.
C. the baseclass method will be used.
D. the subclass method will be used.
ANSWER: D

The Boolean expression A >= B is equivalent to which of the following expressions?
A. !(A > B)
B. !(B >= A)
C. !(A < B)
D. A <= B
ANSWER: C

The Boolean expression (A and B) or A is true
A. only when A is true.
B. only when B is true.
C. whenever either A is true or B is true.
D. for all values of A and B.
ANSWER: A

Which among the following is not true about interfaces?
A. Interface can have properties
B. Interface cannot have access modifiers
C. Interface can have fields
D. All the above
ANSWER : C


Suppose class A implements interface I1. The class explicitly implements a member of I1. How is it possible to access this member?
A. through a class instance
B. through an instance of interface
C. Both the above
D. None
ANSWER : B


Can abstract classes be inherited?
A. Yes
B. No
ANSWER : A


Can we have abstract methods in a normal class?
A. Yes
B. No
ANSWER : B


Can we have static members in an abstract class?
A. Yes
B. No
ANSWER : A


Can an abstract class have protected access modifier
A. Yes
B. No
ANSWER : A


Can an abstract class implement an interface?
A. Yes
B. No
ANSWER : A


Which among the following is true about the New keyword?
A. Used to create objects on the heap and invoke constructors
B. Used to hide an inherited member from a base class member
C. 1 and 2 are true
D. None
ANSWER : C


Can you have a non-static method in a static class?
A. Yes
B. No
ANSWER : B


Can a static class implement interface?
A. Yes
B. No
ANSWER : B


Can a static class contain protected members?
A. Yes
B. No
ANSWER : B


Can you declare an instance member in a static class?
A. Yes
B. No
ANSWER : B


Static classes are sealed.
A. True
B. False
ANSWER : A


You can forcefully call a static constructor.
A. True
B. False
ANSWER : B


Interfaces cannot have static members.
A. True
B. False
ANSWER : A

2 comments: