1) What is the correct way to declare a Java main method?
a) public static void Main(String[] args)
b) public void main(String args)
c) public static void main(String[] args)
d) private static void main(String args[])
2) What is the output of the following Java program?
Java:
public class Geeks
{
public static void main(String[] args)
{
int number = 10;
[Link](Number);
}
}
a) 10
b) Compilation Error
c) Runtime Error
d) Undefined Behavior
3) Which of the following is NOT a valid Java keyword?
a) class
b) define
c) this
d) final
4) What will be the output of the following Java snippet?
public class Geeks
{
static int $count = 5;
public static void main(String[] args)
{
[Link]($count);
}
}
a) 5
b) Compilation Error
c) Runtime Error
d) Undefined Behavior
4) What is the output of the following Java program?
a) 20
b) Compilation Error
c) Runtime Error
d) Undefined Behavior
5) Which of the following is a valid identifier in Java?
a) 123abc
b) @value
c) myVariable
d) void
6) Which package contains the core classes for Java IO?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
7) What does the read() method of FileInputStream return when the end of file is reached?
a) '0'
b) 0
c) -1
d) null
8) What is the output of this snippet?
File f = new File("[Link]");
[Link]([Link]());
a) true if file exists
b) Always true
c) Always false
d) Compilation error
9) Which is the correct hierarchy?
a) FileReader → Reader → Writer
b) FileInputStream → InputStream → OutputStream
c) FileWriter → Writer → OutputStream
d) FileReader → InputStream → Reader
10) In Java networking, which of the following classes is used to implement the client-side socket?
a) Server Socket
b) Socket
c) Datagram Socket
d) InetAddress
11) Which of the following classes in Java is used for sending UDP packets?
a) Socket
b) Datagram Socket
c) Server Socket
d) URL Connection
12) What will be the output of the following code?
class MyThread extends Thread {
public void run() {
[Link]("Thread is running");
}
public static void main(String[] args) {
MyThread t = new MyThread();
[Link]();
}
}
a) Runtime Exception
b) Compilation Error
c) No Output
d) Thread is running
13) What is the role of the __metaclass__ attribute in Python?
a) To define class properties
b) To specify the superclass of a class
c) To indicate the metaclass of a class
d) To restrict the creation of new attributes in an instance
14) What is the output of the following program?
set1 = {3, 4, 5}
[Link]([1, 2, 3])
print(set1)
a) {1,2,3,4,5}
b) {3,4,5,1,2,3}
c) {1,2,3,3,4,5}
d) Error
15) What is the output of the following program?
set1 = set([1, 2, 4, 4, 3, 3, 3, 6, 5])
print(set1)
a){1,2,4,4,3,3,3,6,5}
b){1,2,3,4,5,6}
c)[1,2,3,4,5,6]
d)[ 1,2,4,4,3,3,3,6,5]
16) Find the output of the following program:
nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv']
pos = [Link]("GeeksforGeeks")
print (pos * 3)
a) GeeksforGeeks GeeksforGeeks GeeksforGeeks
b) Harsh
c) Harsh Harsh Harsh
d) ValueError:\’GeeksforGeeks\’is not in list
17) Find the output of the following program:
def REVERSE(a):
[Link]()
return(a)
def YKNJS(a):
b = []
[Link](REVERSE(a))
print(b)
a = [1, 3.1, 5.31, 7.531]
YKNJS(a)
a) [1, 3.1, 5.31, 7.531]
b)[7.531, 5.31, 3.1, 1]
c) IndexError
d) AttributeError: ‘NoneType’ object has no attribute ‘REVERSE’
18) What is the output of the following python code?
head = Node(1)
[Link] = Node(2)
[Link] = Node(3)
current = head
while [Link] and [Link]:
current = [Link]
[Link] = None
a) The list becomes 1 -> 2 -> 3.
b) The list becomes 1 -> 2.
c) The list becomes 2 -> 3.
d) The list becomes 1.
19) What does the following function do for a given Linked List with first node as head?
def fun1(head):
if head is None:
return
fun1([Link])
print([Link], end=' ')
a) Prints all nodes of linked list in reverse order
b) Prints all nodes of linked list
c) Prints alternate nodes in reverse order
d) Prints alternate nodes of Linked List
20) Consider the following function that takes reference to head of a Doubly Linked List as
parameter. Assume that a node of doubly linked list has previous pointer as prev and next pointer
as next.
def fun(head_ref):
temp = None
current = head_ref[0]
while current is not None:
temp = [Link]
[Link] = [Link]
[Link] = temp
current = [Link]
if temp is not None:
head_ref[0] = [Link]
What action will be performed by the following code?
a) Set the value of head_ref to next;
b) Set the value of head_ref to NULL;
c) Set the value of head_ref to current;
d) Set the value of head_ref to prev;
21) What is the time complexity of searching for an element in a linked list?
a) O(1)
b) O(n^2)
c) O(log n)
d) O(n)
22) In a singly linked list, what does the last node’s next pointer point to?
a) A random node
b) The first node
c) A NULL value
d) The second node
23) What will the following list comprehension output?
words = ['apple', 'banana', 'cherry']
word_lengths = {word: len(word) for word in words if len(word) % 2 == 0}
a) {'apple': 5, 'banana': 6, 'cherry': 6}
b) {'apple': 5, 'banana': 6}
c) {'apple': 5, 'cherry': 6}
d) {'banana': 6, 'cherry': 6}
24) What will the following list comprehension output?
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
filtered = [row[1] for row in matrix if row[1] % 2 == 0]
a) [2, 5, 8]
b) [1, 4, 7]
c) [2, 4, 6, 8]
d) [1, 2, 3]