Java exam

profileelpsy69
Mcqs1-6.docx

Mcqs :

Q1:

Suppose we have a queue q (front to back: 2, 4, 6, 8, 10) and an initially empty stack s. We remove the elements from the queue q one at a time and add them to s, until q becomes empty. Next, we remove the elements from s one by one and put them in queue q, until s becomes empty. What does q (front to back) look like now?

Q2:

Consider an implementation of a queue based on a circular table. Suppose we set the maximum capacity of the queue to 5, or MAX_QUEUE_SIZE = 5. In other words, the underlying array will have 5 elements, indexed 0, 1, 2, 3, 4. We define the queue as follows :

CircularArrayQueue <String> queue = new CircularArrayQueue <String> ();

Suppose the queue front variable is initially set to 0, as shown below.

What will be the internal state of the array in the queue after executing the following sequence of operations?

queue.enqueue("X"); queue.enqueue("Z"); queue.enqueue("S"); queue.dequeue(); queue.enqueue("V"); queue.dequeue(); queue.enqueue("C"); queue.enqueue("N"); queue.dequeue();

Q3:

Either the following code:

Which of the following options is correct?

Question 3 options:

This code is correct (it can be compiled and executed)

This code is not correct (it cannot be compiled and executed)

Q4:

What is the result of the following program?

Q5:

What is the result of the following program?

Q6:

What is the result of the following program?