Showing 61–70 of 654 questions
What will be the output of the following code snippet?
int x = 5;
int y = ++x + x++ + x;
System.out.println(y);
EXPLANATION
++x makes x=6, then 6 is added. x++ uses 6 then increments to 7. Finally +x adds 7. So: 6 + 6 + 7 = 19.
Four friends A, B, C, and D have different salaries. C earns more than A but less than D. B earns more than D. Who has the highest salary?
EXPLANATION
From given conditions: A < C < D and D < B. This means B > D > C > A. Therefore, B has the highest salary.
If PAPER is coded as 16-1-16-5-18, then PENCIL would be coded as?
A
16-5-14-3-9-12
B
16-5-13-3-9-12
C
15-5-14-3-9-12
D
16-5-14-2-9-12
Correct Answer:
A. 16-5-14-3-9-12
EXPLANATION
Each letter is coded as its position in the alphabet: P=16, A=1, P=16, E=5, R=18. Similarly, PENCIL: P=16, E=5, N=14, C=3, I=9, L=12.
In a sequence, each term is obtained by adding the previous two terms. If the 1st term is 2 and 2nd term is 3, what is the 6th term?
EXPLANATION
Fibonacci-like sequence: T1=2, T2=3, T3=5, T4=8, T5=13, T6=21. Each term = sum of previous two terms.
A train travels from City A to City B at 60 km/h and returns from B to A at 40 km/h. If the total journey time is 10 hours, what is the distance between City A and City B?
A
240 km
B
300 km
C
280 km
D
320 km
Correct Answer:
A. 240 km
EXPLANATION
Let distance = d km. Time A to B = d/60 hours, Time B to A = d/40 hours. Total time: d/60 + d/40 = 10. LCM(60,40)=120, so (2d + 3d)/120 = 10, giving 5d/120 = 10, thus d = 240 km.
What does the SELECT * query do in SQL?
A
Selects the first row
B
Selects all columns from all rows
C
Selects only the primary key
D
Deletes all data
Correct Answer:
B. Selects all columns from all rows
EXPLANATION
SELECT * retrieves all columns and rows from a table. * is a wildcard meaning 'all columns'.
Which protocol is used for secure data transmission over the internet?
A
HTTP
B
HTTPS
C
FTP
D
SMTP
EXPLANATION
HTTPS (HTTP Secure) encrypts data in transit using SSL/TLS. Other protocols lack this encryption.
What is the time complexity of accessing an element in a balanced Binary Search Tree?
A
O(1)
B
O(log n)
C
O(n)
D
O(n²)
Correct Answer:
B. O(log n)
EXPLANATION
In a balanced BST, the height is log n, so searching takes O(log n) time.
If a HashMap has 1000 entries and the load factor is 0.75, at what capacity will it resize?
A
750
B
1000
C
1333
D
Cannot be determined
EXPLANATION
Resize occurs when entries exceed capacity × load factor. If 1000 entries at 0.75 load factor, capacity = 1000/0.75 = 1333
What is the purpose of the 'try-catch' block in Java?
A
To improve code performance
B
To handle exceptions gracefully
C
To declare variables
D
To create loops
Correct Answer:
B. To handle exceptions gracefully
EXPLANATION
try-catch blocks allow you to handle exceptions without crashing the program, providing graceful error handling.