ML01

¡Supera tus tareas y exámenes ahora con Quizwiz!

Four values- ONE, TWO, THREE, and FOUR are pushed in that order into a stack that is initially empty. Zero or more "pop"s may occur between each "push". For example the sequence of operations below would produce the order of values popped from the stack as: TWO THREE FOUR ONE push ONE push TWO pop push THREE pop push FOUR pop pop If THREE is the first value popped from the stack, which of the following is the possible order of the values popped from the stack (i) THREE FOUR TWO ONE (ii) THREE ONE FOUR TWO (iii) THREE TWO FOUR ONE (iv) THREE ONE TWO FOUR

(i) and (iii) only

Consider a single linked list, which of the following operation depend on the length of the linked list? -Delete the first item of the linked list -Add an item before the first item of the linked list -Delete the last item of the linked list -Add an item after the last item of the linked list

-Delete the last item of the linked list. -Add an item after the last item of the linked list.

The default value of a static integer variable of a class in Java is

0

Consider the following function. void Repeat(int n) { if (n >= 2) { Repeat(n / 3); } cout << n << " "; } Which of the following is output as a result of the call Repeat(27) ?

1 3 9 27

What is the output of the following program: public class testmeth { static int i = 1; public static void main(String args[]) { System.out.println(i+" , "); m(i); System.out.println(i); } public void m(int i) { i += 2; } }

1, 1

void printNum(int n, int base) { cout << n MOD base; if (n >= base) printNum( n / base, base ); } What is the output generated for printNum(123, 8);

371

A typical Queue implementation has 3 operations; They are: enqueue(), dequeue(), and Front(). -Enqueue() will add an item to the end of the queue. -Dequeue() will remove and return an item from the beginning of the queue -Front() will return the value of front-most item. What values would be returned after the following sequence of operations: enqueue(4), enqueue(8), dequeue(), enqueue(98), enqueue(15), dequeue(), dequeue(), enqueue(5), enqueue(2), front()

4,8,98,15

Which of the following is true? -A finally block is executed whether an exception is thrown or not -A finally block is executed before the catch block but after the try block -A finally block is executed, only after the catch block is executed -A finally block is executed, only if an exception occurs

A finally block is executed whether an exception is thrown or not

Which of the following is NOT true in java language? -A protected member of a class can be accessed from its derived class -A private member of a class cannot be accessed from its derived class -A public member of a class can be accessed in all the packages -A private member of a class cannot be accessed by the methods of the same class

A private member of a class cannot be accessed by the methods of the same class

The following incomplete function is intended to return the index of the first occurrence of the minimum value in the array A. { int k; int minIndex = 0; for (k = 1; k < A.length(); k++) { if ( <condition> ) { <statement> } } return minIndex; } Which of the following could be used to replace <condition> and <statement> so that function works as intended? <condition> <statement> - A[k] < A[minIndex] minIndex = A[minIndex]; - A[k] < A[minIndex] minIndex = k; - A[k] < minIndex minIndex = A[k]; - A[k] > minIndex minIndex = A[k];

A[k] < A[minIndex] minIndex = k;

Which of the following statement(s) is/are correct about Exception Handling? -Exception handling codes are separated from "Regular" code. -It propagates error reporting up to the call stack of methods. -All of the listed. -Exception occurs during program execution time.

All of the listed.

Which of the following mechanisms is/are provided by Object Oriented Language to implement Object Oriented Model? -Inheritance -All of the mentioned -Polymorphism -Encapsulation

All of the mentioned

Which one of the following is not true? -A class containing abstract methods is called an abstract class -Abstract methods should be implemented in the derived class -An abstract class cannot have non-abstract methods -A class must be qualified as 'abstract' class, if it contains one abstract method

An abstract class cannot have non-abstract methods

Which of the following is NOT true? -An interface is a solution for multiple inheritance in java -An interface can extend another interface -A class which is implementing an interface must implement all the methods of the interface -An interface can implement another interface

An interface can implement another interface

Consider an example of Teacher and Student. What best describes the relationship of "Student" to "Teacher" -Aggregation -Association -Inheritance -Coterm-28mposition

Association

Are there any dynamic memory management errors in the following code? int *p = new int; int *q = new int; int *r; *p = 17; r = q; *q = 42; p = q; delete r; A) No, there are no errors B) Yes, a memory leak C) Yes, misuse of a dangling pointer D) Yes, both a memory leak and misuse of a dangling pointer E) Yes, a dangling chad

B) Yes, a memory leak

What is the complexity of the following code expressed in O( ) notation? If more than one answer is correct, choose the smallest one. for (int j = n; j > 0; j--) { for (int k = 1; k < j; k = k+k) { cout << j+k << " "; } cout << endl; } A) O(log n) B) O(n) C) O(n log n) D) O(n2) E) O(2n)

C) O(n log n)

int total = 0; for (k = 0; k < A.length(); k++) { if(A[k] % 2= =0) total=total+1 } return total; Assume that "A" is defined as an integer array; What does the above code return;

Count of the elements which are even

Indicate which of the statements are True? Iterm-26. A subclass inherits private methods from its superclass. II. A private member is invisible outside of the unit or program where its class is declared III. A public member is visible wherever its class can be referenced IV. A protected member is visible anywhere in the module where its class is declared and from any descendant class, regardless of the module where the descendant class appears.

II, III, and IV only

What is the difference between an object and a class? I. An object is an extension of the class construct whose default access privilege is public. II. The term object is just another way of referring to the public data members of a class. III. An object is an initialized class variable. Iv. A class is an initialized object variable.

III

Which of the following is a mechanism by which object acquires the properties of another object? -Encapsulation -Polymorphism -Inheritance -Abstraction

Inheritance

Which of the following(s) is/are correct description of a linked list data type? -Linked list is a fixed-size data structure. -Linked list requires O(log n) running time for data search in the worst-case. -Linked list provides an index to access the elements in the list. -Linked list requires O(n) running time for data insertion/deletion in the worst-case.

Linked list requires O(n) running time for data insertion/deletion in the worst-case.

long factorial( int n ) { if( n <= 1 ) return 1; else return (factorial(n) * factorial( n - 1 )); } What is the value returned for factorial(4);

Logical error

Which of the following concept is often expressed by the phrase, 'One interface, multiple methods'? -Inheritance -Encapsulation -Abstraction -Polymorphism

Polymorphism

What does the following function do for a given Linked List with first node as head? void fun1(struct node* head) { if(head == NULL) return; fun1(head->next); printf("%d ", head->data); }

Prints all nodes of linked list in reverse order

Which of the following(s) is/are the benefits of recursive method?

Recursion enables us to write simple, clear solution for inherently recursive problems that would otherwise be difficult to solve.

Which of the following is the functionality of 'Data Abstraction'? -None of the mentioned -Binds together code and data -Parallelism -Reduce Complexity

Reduce Complexity

How will a class protect the code inside it?

Using Access specifiers

Suppose you need to write a program that stores a fixed number of the elements (possibly has duplicates), what data structure should you consider to use?

array list

The fields in an interface are implicitly specified as

both static and final

What is the value of the postfix expression 6 3 2 4 + - *? a) 1term-24 b) 40 c) 74 d) -18 e) 18

d) - 18

When a class serves as base class for many derived classes, the situation is called

hierarchical inheritance

When two or more classes serve as base class for a derived class, the situation is known as

multiple inheritance


Conjuntos de estudio relacionados

CC6003 Digital Crime Investigation quiz 6, CC6003 Digital Crime Investigation quiz 4, Digital Crime Investigation quiz 5, CC6003 Digital Crime Investigation quiz 3, DCI Review Questions 2, DCOM258: Quiz6: Networking Protocols and Threats(Ch7)

View Set

Anatomy Lecture Chapter 9 and terms

View Set