Câu hỏi Ôn Tập Quarter 4
1. What types of values are stored in a node of a doubly-linked list?
a. Only dada contained in the node
b. Address of the succeeding node only along with some data
c. Address of the preceding node only along with some data
d. Address of the preceding and succeeding node with some data
2. Which of the following is an example of a recursive function?
a. f(n) = 0
where n >1; and f(1) =1
b. f(n +1) = n
where n >1; and f(1) =1
c. f(n) = n
where n >1; and f(1) =1
d. f(n) = f(n - 1) +n
where n >1; and f(1) =1
3. In a binary tree, a node with no children is call a………..
a. Subtree
b. Parent node
c. Internal node
d. Leaf node
4. Which of the following is NOT correct about assertion?
a. Assertions are a way to test certain assumtions about the logic
of a program
b. Assertions occupy space in class file and increases the
download time
c. Assertions describe how to hanle unexpected errors
d. Assertions can be enabled during program development
5. Which of the following is a condition for queue overflow?
a. FRONT = 1 and REAR = last index position
b. FRONT = REAR
c. FRONT = 0 and REAR = last index position
d. FRONT = 0 and REAR = first index position
6. Which of the following method will you call to set the size of a
Frame ?
a. Pack()
b. setVisible()
c. setSize()
d. setLayout()
Good Luck Page 1
7. Henry has to write a program to store and display a list of prime
numbers in a singly-linked list. According to the requirement, the
insert operation always need to be done at the end of the list.
Therefore Hanry decides to use two variables, START and LAST,
to keep track of the first and the last nodes in the list. Identify the
correct algorithm that would enable Henry to insert values at the
end of the linked list.
a. 1. Alloacte memory for the new node
2. Assign value to the data field of the new node
3. If START is NULL, then:
a. Make START point to the new node
b. Make LAST point to the new node
c. Go to step 6
4. Make the next field of LAST point to the new node
5. Mark the new node as LAST
6. Make the next field of the new node point to NULL
b. 1. Alloacte memory for the new node
2. Assign value to the data field of the new node
3. If START is NULL, then:
a. Make START point to the new node
b. Make LAST point to the new node
c. Go to step 6
4. Make the next field of START point to the new node
5. Mark the new node as START
6. Make the next field of the new node point to NULL
c. 1. Alloacte memory for the new node
2. Assign value to the data field of the new node
3. If START is NULL, then:
a. Make START point to the new node
b. Make LAST point to NULL
c. Go to step 6
4. Make the next field of LAST point to the new node
5. Mark the new node as LAST
Make the next field of the new node point to NULL
d. 1. Alloacte memory for the new node
2. Assign value to the data field of the new node
3. If START is NULL, then:
a. Make START point to the new node
b. Make LAST point to the new node
c. Go to step 6
Good Luck Page 2
4. Mark the new node as LAST
5. Make the next field of LAST point to the new node
6. Make the next field of the new node point to NULL
8. Consider the following code:
public class Calculate {
public static void main(String [] agrs){
try{
int total =0;
for(int i =0; i<[Link];i++){
total +=
[Link](agrs[i]);
}
[Link]("Total is " +
total);
}
catch(NumberFormatException nfe){
[Link]("Incorrect
argument");
}
}
}
What will be the output of the iven code when the program is run
with argument 1,two, and 3?
a. The code complies successfully and displays The total is 4.
b. The code complies successfully and displays an error message
Incorrect argument
c. The code complies successfully and displays The total is 0
d. The code givens a compilation error.
8. Identify the correct syntax used to instantiate the Thread class.
a. newThread = new Thread (this,”threadName”);
b. Thread newThread = new Thread (this,”threadName”);
c. Thread newThread = Thread (“threadName”);
d. Thread newThread = new(this);
9. <Keyboard buffering is an application of which the following data
structures?
a. Queues
b. Linked List
c. Trees
d. Stacks
Good Luck Page 3
[Link] of the following is a valid java identifier?
a. Long
b. Const
c. New
d. $const
11.A class Shape has a method draw(). Three classes, Rectangle,
Square, and Circle will be derived from the Shape class. What
will you do to force the subclasses to override the draw() method?
a. Specfy draw() as an interface and Rectangle, Square, and circle
should extend the Shape Class.
b. Specfy Shape as final and Rectangle, Square, and Circle should
implement the Shape Class.
c. Specfy Shape as an interface and Rectangle, Square, and Circle
should implement the Shape Class.
d. Specfy draw() as abstract and Rectangle, Square, and circle should
extend the Shape Class.
[Link] is the correct algorithm to delete a leat node from a
threaded birary tree if the node to be delected is the left child of
its parent?
(Assume that the node to be deleted is marked as currentNode
and its parent is marked as parent. Also, the parent in this case is
not the header node)
a. 1. Set the left thread field of parent as zero
[Link] the right child field of parent as a thread pointing to the
inorder successor of currentNode.
3. release the memory for currentNode
b. 1. Set the left thread field of parent as zero
[Link] the right child field of parent as a thread pointing to the
inorder successor of currentNode.
3. release the memory for currentNode
c. 1. Set the left thread field of parent as zero
[Link] the left child field of parent as a thread pointing to the
inorder predecessor of currentNode.
3. Release the memory for currentNode
d. 1. Set the left thread field of parent as zero
[Link] the left child field of parent as a thread pointing to the
inorder predecessor of currentNode.
3. Release the memory for currentNode
13. Consider the following statements on threads:
Good Luck Page 4
Statement A: You can create a new thread by extending the Thread class
Statement B: You can create a new thread by implementing the Runnable
interface
Select the correct option for the preceding staterents.
a. Both Statement A and Statement B are false
b. Statement A is false while Statement B is true
c. Both Statement A and Statement B are true
d. Statement A is true while Statement B is false
[Link] the code:
public class TestSwitch{
public static void main(String args[]){
int x = 10;
if(x>15)x=1;
switch(x){
case 10: [Link](10);
case 1: [Link](1);
case 2: [Link](2);
break;
case 3: [Link](3);
default: [Link](4);
break;
}
}
}
What is the output of given code?
a. 10
1
2
3
b. 10
1
2
3
4
c. 10
1
2
d. 1
2
Good Luck Page 5
[Link] X and Y are the sub classes of class A. Class A has a method
defined as accessMe(). Class X is with n the sme package as Class
A where as class Y is in some other package. The method
accessMe() is accessible to class X but not to class Y. What is the
access specifier defined to accessMe() method?
a. Protected friend
b. Friendly
c. Protected
d. Private
[Link] works as a techical support officer in BlueMoon Inc. I
receives a lot of hardware- related queries on daily basis, which
need to be manaced in such a way so that the query that comes
firs should be solved first. As a part of the development team, you
are assigned a task to solve this problem by writing an
appropriate algorithmn to store the queries in the form of a
singly-linked lit. The algorithm should store the incoming queries
in such a way so that the quer, which should be implement to
accomplish this task.
a. 1. Allocate memory for the new node. This node would represent a
new query
2. Assign value to the data field of the new node
3. Make the next field of the rew node point to Null
4. if the list is empty execute the following steps:
• Make a variable/pointer, Front, point to the new node //Front
keeps track of the element that was inserted first
• Make a variable/ pointed, Rear, point to the new node// Rear
keeps track of the element that was inserted last
• Exit
5. Make the next field of REAR point to the new node
6. Make FRONT point to the new node
b. 1. Allocate memory for the new node. This node would represent a
new query
2. Assign value to the data field of the new node
3. Make the next field of the new node point to Null
4. if the list is empty execute the following steps:
• Make a variable/pointer, Front, point to the new node //Front
keeps track of the element that was inserted first
Good Luck Page 6
• Make a variable/ pointed, Rear, point to the new node// Rear
keeps track of the element that was inserted last
• Exit
5. Make the next field of REAR point to the new node
6. Make REAR point to the new node
c. 1. Allocate memory for the new node. This node would represent a
new query
2. Assign value to the data field of the new node
3. Make the next field of the rew node point to Null
4. if the list is empty execute the following steps:
• Make a variable/pointer, Front, point to the new node //Front
keeps track of the element that was inserted first
• Make a variable/ pointed, Rear, point to the new node// Rear
keeps track of the element that was inserted last
• Exit
5. Make the next field of FRONT point to the new node
6. Make FRONT point to the new node
[Link] the following code:
import [Link];
import [Link];
import [Link];
public class Example {
public static void main (String []
args)throws IOException{
FileInputStream in = null;
FileOutputStream out = null;
try{
in = new
FileInputStream("[Link]");
out = new
FileOutputStream("[Link]");
int c;
while((c=[Link]())!= -1){
[Link](c);
}
}
finally{
if(in != null){
Good Luck Page 7
[Link]();
}
if(out != null){
[Link]();
}
}
}
}
What will be the output of the above?
a. The code will execute without any output
b. The code will throw a runtime exception
c. The code will copy the content of the [Link] file to the
[Link] file
d. The code will copy the content of the [Link] file to the
[Link] file
17. Jim wants to calculate the address of an element stored at 9th
position in an array. Assuming the base address to be 10 and the
size of an element to be 2, calculate the address of an element
stored 9th position in an array.
a. 29
b. 92
c. 280
d. 28
[Link] the following statements:
Statement A: An Error class is derived from an Exception class
Statement B: Error class is used for VirtualMachineError
Which of the following options is true with respect to above
statement?
a. Statement A is True and Statement B is False
b. Both the Statement are True
c. Statement A is False and Statement B is True
d. Both the Statement are False
19. Which of the following code will compile, execute, and display the
word Hello?
a. public class Example{
public static void main(String args[]){
Good Luck Page 8
String str1 =”hello”;
String str2 =”Hello”;
If ([Link](str2)){
[Link](“Hello”);
}
}
}
b. public class Example{
public static void main(String args[]){
int num1;
int num2;
if(num1 == num2){
[Link](“Hello”);
}
}
}
c. public class Example{
public static void main(String args[]){
String str1 =”Hello”;
String str2 =”Hello”;
If (str1 == str2){
String str2 = new String(“Hello”);
[Link](“Hello”);
}
}
}
d. public class Example{
public static void main(String args[]){
String str1 =”Hello”;
String str2 =”Hello”;
If (str1 == str2){
[Link](“Hello”);
}
}
}
[Link] option shows the allowed data type of a variable in the
swith-case construct?
a. boolean
Good Luck Page 9
b. byte
c. double
d. Float
21. Which of the following sorting techniques will use, if the list to be
sorted is small in size and is nearly sorted?
a. Insertion Sort
b. Bubble Sort
c. Quick Sort
d. Selection Sort
[Link] a binary tree consisting of 8 nodes. How many edges are
therer in this binary tree?
a. 9
b. 7
c. 8
d. 6
[Link] the following statements:
Statement A: A List can contain duplicate elements
Statement B: A Set contains unique elements
Which of the following is True, with respect to the above Statement?
a. Both, Statement, A and B, are True
b. Statement A is True and Statement B is False
c. Both, Statement, A and B, are True
d. Statement A is False and Statement B is True.
24. If an algorithm is of the order of O (log n), then the algorithm has
a _____ order of growth.
a. Log Linear
b. Constant
c. Exponential
d. Logarthmic
25._______is the immediate superclass of the MouseEvent class
a. InputEvent
b. AWTEvent
c. ActionEvent
d. FocusEvent
[Link] of the Statement is used to run a java code?
a. java<filename>.java
b. java<filename>
c. javac<filename>.java
Good Luck Page 10
d. javac<filename>
[Link] of the following hold true for quick sort algorithm?
a. It works by dividing the list into two sublist of sizes as naerly
equal as possible, and then the two sublists are sorted separately
b. It works by selecting an element from the list called a pivod and
then partitioning the list into parts that’s may or may not be equal
c. It works by repertedly scanning through the list, comparing
adjacent elements, and swapping them if they are in the wrong
order.
d. Its works by scanning through the list iteratively,selecting one item
in each scan, and moving the item to its corresposition in the list
[Link] the following statements:
Statement A: Keywords are always written in uppercase in java
Statement B: Keywords cannot be used as variable names.
Which of the following is true, with respect to the above Statements?
a. Statement A is True and Statement B is False
b. Both, Statement, A and B, are False
c. Both, Statement, A and B, are True
d. Statement A is False and Statement B is True
[Link] the following code, where MyListener is a listener class of
action events:
Frame f = new Frame(“Frame”);
MenuBar m1 = new MenuBar();
Menu menu1 = new Menu(“File”);
[Link](new MyListener);
[Link](menu1);
[Link](m1);
select the correct option regarding the preceding code.
a. The code will add an action listener to both the menu bar and the
File menu
b. The code will add an action listener to the frame
c. The code will add an action listener to the menu bar
d. The code will add an action listener to only the menu bar and the
File menu
[Link] is a circular linked list?
a. Circular linked list is a dyamic data structure in which each node
points to the next node in its sequence as well as its preceding
node, and the last node points to NULL.
b. Circular linked list is a static data structure in which each node
points to the next node in sequence and the last node points NULL
Good Luck Page 11
c. Circular linked list is a dyamic data structure in which each node
points to the next node in sequence and the last node points to the
first node in the list.
d. Circular linked list is a dyamic data structure in which each node
points to the next node in sequence and the last node points to
NULL.
[Link] the following code:
import [Link].*;
public class Example{
public static void main(String [] args)
{
<Class Name> obj= new <Class Name>();
[Link](“Alps”);
[Link](“Alps”);
[Link](obj);
}
}
Which of the following class will you use in the place of <Class
Name> to execute the program with the following output:[Aplas]
a. HashSetMap
b. Arraylist
c. LinkedList
d. HashSet
[Link] many comparisons are required to sort an array of 10
element by using selection sort?
a. 45
b. 9
c. 55
d. 10
[Link] is assigned a task to write code for travaersing a [Link]
traversal, the nodes are displayed in the following sequence:
DFEBCA
Analyze the tree by clicking the Exhibit button and identify the
algorithm that Sam must have used to traverse the tree.
a. Algorith:order(root)
1. If (root = NULL)
a. Exit
2. Visit(root)
3. Order(right child of root)
4. Order(left child of root)
Good Luck Page 12
b. Algorith:order(root)
[Link] (root = NULL)
[Link]
[Link](root)
[Link](left child of root)
[Link](right child of root)
c. Algorith:order(root)
[Link] (root = NULL)
[Link]
[Link](left child of root)
[Link](right child of root)
[Link](root)
d. Algorith:order(root)
[Link] (root = NULL)
[Link]
[Link](left child of root)
3. Visit(root)
4. Order(right child of root)
34. Consider the following code:
public class CurrentThread {
public static void main(String [] args){
Thread thisThread =
[Link]();
try {
for (int counter
=0;counter<10;counter +=2)
{
[Link](" " + counter );
[Link](1000);
}
}
catch(InterruptedException e){
[Link]("Thread
interrupted");
}
}
}
What will be the output of the given code?
a. The code compiles successfully but does not display any output
b. The code gives a compilayion error
Good Luck Page 13
c. 0123456789
d. 02468
[Link] has been assign a task to write code to implement a search
operation on a list of elements for locating a particular value. He
decides to implement linear [Link] the correct algorithm
that would enable John to accomplish his task.
a. 1. Accept the value to be searched
2. set i= 1
3. Repeat step 4 until i>n or arr[i] = value to be searched
4. Increment i by 1
[Link] i>n:
Display”Not Found”
Else
Display” Found”
b. 1. Accept the value to be searched
2. set i= 0
3. Repeat step 4 until i>n or arr[i] = value to be searched
4. Increment i by 1
[Link] i>n:
Display”Not Found”
Else
Display” Found”
c. 1. Accept the value to be searched
2. set i= 0
3. Repeat step 4 until arr[i] = value to be searched
4. Increment i by 1
[Link] i>n:
Display”Not Found”
Else
Display” Found”
d. 1. Accept the value to be searched
2. set i= 0
3. Repeat step 4 until i =n or arr[i] > value to be searched
4. Increment i by 1
[Link] i>n:
Display”Not Found”
Else
Display” Found”
Good Luck Page 14
[Link] is assigned a task to develop a code to display all the contents
of a singly-linked list. He developed the code arrording to the
following algorithm:
Step I: Make currentNode point to the first node in the list
Step II: Repeat steps III and IV until currentNode becomes NULL
Step III: Make currentNode point to the next node in sequence
Step IV: Display the information contained in the node marked as
currentNode
However, the code does not give the desired output. Identify the problem
in the preceding algorithm.
a. The sequence of steps III and IV is incorrect
b. Step II is incorrect. The correct statement should be ‘Repeat step III
until the next field of currentNode becomes NULL’
c. Step II is incorrect. The correct statement should be ‘Repeat step III
and step IV until the next field of currentNode becomes NULL’
d. Step IV is incorrect. The correct statement should be ‘Display the
information contained in the successor of the node marked as
currentNode’
[Link] the following algorithm to implement Bubble sort in
ascending order on an array:
1. Set pass=1
2. Repeat step 3 varying j from 1 through n-pass
3. If the element at index j is greater than the element at index j +1,
swap the two elements
4. Increment pass by 1
5. If pass < n go to step 2
Identify whether the preceding algorithm will provide the desired
result or not? Also suggest the correct solution in case of error
a. The algorithm will provide the desired output
b. The algorithm will not provide the desired [Link] 5 should
be “If pass <= n go to step 2”
c. The algorithm will not provide the desired [Link] 3 should
be “If the element at index j-1 is greater than the element at
index j, swap the two elements”
d. The algorithm will not provide the desired [Link] 1 should
be Set pass=0.
[Link] is assigned a task to develop a code to evaluate a postfix
expression. He decides to implement a stack for the same. To
accomplish this task, he writes a code based on the following
algorithm:
Good Luck Page 15
1. Initialize the stack to be empty
2. Scan the entries in the infix expression from left to right until the
end of the infix expression is encountered:
a. If an operand infix is encountered, POP it from the stack
b. If an operator is encountered:
i. POP the top two values
ii. Operate the two values by using the operator
iii. PUSH the result to the stack
3. Get result from the top of the stack
However, he does not get the desired result. Identify the problem
in the algorithm
a. Sequence of Steps 2(a) and 2(b) is incorrect
b. Steps 2(a) is [Link] this step, if an operand is encountered,
it should be discarded…
c. Steps 2(a) is [Link] this step, if an operand is encountered,
it should be pushed into the stack
d. Steps 1is incorrect. The stack should not be made empty
Good Luck Page 16