1.
Consider a linked list implemented of a queue with two pointers: front and rear. What is the time needed to insert element in a queue of length of n?
Correct Answer
A. O(log2n)
Explanation
The correct answer is O(n). In a linked list implementation of a queue, inserting an element involves updating the rear pointer to point to the new element. This operation takes constant time, regardless of the length of the queue. Therefore, the time complexity for inserting an element in a queue of length n is O(1), not O(log2n).
2.
Time taken for addition of element in queue is
Correct Answer
B. O(n)
Explanation
The time taken for the addition of an element in a queue is O(n). This means that the time complexity is directly proportional to the number of elements in the queue. As the number of elements increases, the time taken for adding an element also increases. This is because in a queue, new elements are added at the rear end, and if the queue is already full, additional memory needs to be allocated and all the existing elements need to be shifted to accommodate the new element. Therefore, the time complexity for adding an element in a queue is O(n).
3.
The statement that tests to see if sum is equal to 10 and total is less than 20, and if so, prints the text string "incorrect.", is
Correct Answer
C. if( (sum == 10) ¦¦ (total < 20) )printf(
Explanation
The correct answer is "if( (sum == 10) ¦¦ (total < 20) )printf(". This statement checks if the variable "sum" is equal to 10 and the variable "total" is less than 20. If both conditions are true, it will print the text string "incorrect". The double vertical bar "¦¦" represents the logical OR operator, which means that if either condition is true, the overall expression will be true.
4.
Consider a linked list of n elements. What is the time taken to insert an element pointer ?
Correct Answer
A. O(n log2n)
Explanation
The time taken to insert an element pointer in a linked list of n elements is O(n log2n). This means that the time complexity of the insertion operation is directly proportional to the number of elements in the linked list, multiplied by the logarithm (base 2) of the number of elements. This suggests that as the number of elements in the linked list increases, the time taken to insert an element pointer will also increase, but at a slower rate than linearly.
5.
Which is a logical abstract base class for a class called "footballPlayer"?
Correct Answer
B. Team.
Explanation
The logical abstract base class for a class called "footballPlayer" would be "Team". This is because a football player is typically a part of a team and the team serves as the higher-level concept or category that the football player belongs to.
6.
Can two classes contain member functions with the same name?
Correct Answer
C. Yes, but only if the two classes have the same name.
Explanation
Yes, two classes can contain member functions with the same name, but only if the two classes have the same name. This is because member functions are identified by their class name, so if two classes have the same name, their member functions can have the same name as well. However, if the classes have different names, their member functions must also have different names to avoid conflicts.
7.
A derived class is
Correct Answer
A. Inherits data members and member functions from base class.
Explanation
A derived class is a class that inherits data members and member functions from a base class. This means that the derived class can access and use the same data members and member functions as the base class. It does not inherit constructors and destructors, as those are specific to each class and need to be defined separately.
8.
_________is a relationship
Correct Answer
B. Inheritance
Explanation
Inheritance is a relationship in object-oriented programming where one class inherits the properties and methods of another class. This allows the subclass to reuse the code from the superclass and add its own unique functionality. Inheritance promotes code reusability, as it allows for the creation of specialized classes that inherit common attributes and behaviors from a more general class.
9.
Which is a logical abstract base class for a class called "CricketPlayer"?
Correct Answer
C. Cricket
Explanation
The logical abstract base class for a class called "CricketPlayer" would be "Sports" or "Team". This is because a cricket player is a type of sports player and is also a member of a team. However, "Cricket" cannot be the logical abstract base class as it represents the specific sport itself, rather than a general category that includes the concept of a cricket player.
10.
Maintaining the state of an object is called____.
Correct Answer
A. Serialization
Explanation
Serialization is the process of converting an object into a format that can be stored, transmitted, or reconstructed later. It involves converting the object's state into a byte stream, which can then be saved to a file or sent over a network. By serializing an object, its state is maintained and can be restored at a later time. Therefore, serialization is the correct answer for the given question.
11.
______ means that both the data and the methods which may access it are defined together in the same unit.
Correct Answer
B. Encapsulation
Explanation
Encapsulation means that both the data and the methods which may access it are defined together in the same unit. This allows for better organization and control over the data, as it is encapsulated within the unit and only accessible through the defined methods. This helps to prevent direct access to the data from external sources and ensures that any changes to the data are done through the appropriate methods, providing better security and maintainability of the code.
12.
If a catch statement is written to catch exception objects of a base class type, it can also catch all _____ derived from that base class
Correct Answer
C. Exceptions for objects
Explanation
If a catch statement is written to catch exception objects of a base class type, it can also catch all exceptions derived from that base class. This is because when an exception is derived from a base class, it inherits the properties and behaviors of that base class. Therefore, if a catch statement is designed to catch exceptions for objects, it will be able to handle any exception object that is derived from the base class.
13.
Association in UML can be represented by:
Correct Answer
A. A plane line with no shape on either end.
Explanation
In UML, association represents a relationship between two classes. It is depicted by a plane line with no shape on either end. This indicates that there is a connection between the two classes, but it does not specify the nature or direction of the relationship. The absence of any shape on either end signifies that the association is not navigable from either class.
14.
Suppose that the Test class does not have an overloaded assignment operator. What happens when an assignment a=b; is given for two Test objects a and b?
Correct Answer
B. The copy constructor is used
Explanation
When an assignment a=b; is given for two Test objects a and b, the copy constructor is used. This is because in the absence of an overloaded assignment operator, the default assignment operator provided by the compiler performs a member-wise copy of the data from the source object (b) to the destination object (a). This requires the use of the copy constructor to create a new object (a) with the same values as the source object (b).
15.
Peer-to-peer relationship is a type of _________.
Correct Answer
C.
3) Link
Explanation
A peer-to-peer relationship refers to a type of connection or link between two or more peers, where each peer has equal privileges and responsibilities. This relationship is characterized by a decentralized structure, where peers can communicate and share resources directly with each other without the need for a central authority. Therefore, the correct answer is "Link".
16.
An application uses encapsulation to achieve ________
Correct Answer
A. Information hiding
Explanation
Encapsulation is a concept in object-oriented programming that involves bundling data and methods together into a single unit called an object. This helps in achieving information hiding, where the internal details and implementation of an object are hidden from the outside world. By encapsulating data and methods, an application can control access to its internal state and ensure that it is only accessed and modified through defined methods. This helps in maintaining data integrity and allows for easier maintenance and modification of the code. Therefore, the correct answer is information hiding.
17.
A class is_____
Correct Answer
B. Abstract Type
Explanation
An abstract type refers to a class that cannot be instantiated directly, but serves as a base for other classes to inherit from. It provides a common interface and defines common behavior that derived classes can implement. Abstract types are typically used to define common characteristics and behavior for a group of related classes.
18.
Can two classes contain member functions with the same name?
Correct Answer
C. Yes, this is always allowed.
Explanation
Yes, this is always allowed. In object-oriented programming, it is possible for two classes to contain member functions with the same name. This is known as function overloading, where different classes can have functions with the same name but different parameters or return types. The compiler can differentiate between these functions based on their signatures, allowing for more flexible and expressive code.
19.
In object orientated programming a class of objects can _____________ properties from another class of objects
Correct Answer
A. Utilize
Explanation
In object-oriented programming, when a class of objects "utilizes" properties from another class of objects, it means that it is using or making use of those properties. This can be done through inheritance, where one class inherits the properties and methods of another class. By utilizing the properties, the class can access and manipulate the data or behavior defined in the other class, making the code more efficient and reusable.
20.
Reusability can be achieved through.
Correct Answer
B. Composition.
Explanation
Composition is a design principle in object-oriented programming that allows objects to be composed of other objects. It promotes reusability by creating relationships between classes where one class contains another class as a member variable. This allows the containing class to reuse the functionality of the contained class without inheriting from it. Inheritance, on the other hand, allows for code reuse by creating a parent-child relationship between classes. Association is a looser relationship between classes that allows objects to interact, but does not promote code reuse in the same way as composition. Therefore, composition is the correct answer for achieving reusability.