Showing 71–80 of 654 questions
Which of the following is NOT a principle of object-oriented programming?
A
Inheritance
B
Encapsulation
C
Polymorphism
D
Materialization
Correct Answer:
D. Materialization
EXPLANATION
The four OOP principles are Inheritance, Encapsulation, Polymorphism, and Abstraction. 'Materialization' is not an OOP principle.
What is the difference between ArrayList and LinkedList in Java?
A
ArrayList is faster for random access
B
LinkedList is faster for insertions/deletions in middle
C
Both are correct
D
No difference
Correct Answer:
C. Both are correct
EXPLANATION
ArrayList has O(1) random access but O(n) insertion/deletion. LinkedList has O(n) access but O(1) insertion/deletion.
What will be the output?
List list = new ArrayList();
list.add(1);
list.add(2);
list.add(3);
list.remove(1);
System.out.println(list);
A
[1, 3]
B
[1, 2, 3]
C
[2, 3]
D
[1, 2]
Correct Answer:
A. [1, 3]
EXPLANATION
list.remove(1) removes the element at index 1 (which is 2), leaving [1, 3].
Which design pattern is used when you want to ensure a class has only one instance?
A
Factory Pattern
B
Singleton Pattern
C
Builder Pattern
D
Observer Pattern
Correct Answer:
B. Singleton Pattern
EXPLANATION
Singleton Pattern restricts a class to have only one instance and provides a global access point to it.
What is the main advantage of using microservices architecture?
A
Easier to develop and test
B
Better scalability and flexibility
C
Reduced operational complexity
D
All of the above
Correct Answer:
B. Better scalability and flexibility
EXPLANATION
Microservices allow independent scaling, deployment, and technology choices. However, they can increase operational complexity.
In the context of REST APIs, what does POST primarily do?
A
Retrieve data
B
Create new resources
C
Update existing resources
D
Delete resources
Correct Answer:
B. Create new resources
EXPLANATION
POST method is used to create new resources on the server. GET retrieves, PUT/PATCH updates, DELETE removes.
Which of the following is a characteristic of a good hash function?
A
Deterministic behavior
B
Uniform distribution
C
Collision resistance
D
All of the above
Correct Answer:
D. All of the above
EXPLANATION
Good hash functions are deterministic (same input gives same output), uniformly distribute values, and minimize collisions.
What is the primary purpose of a hash function?
A
To encrypt data
B
To map input to a fixed-size output
C
To compress data
D
To sort data
Correct Answer:
B. To map input to a fixed-size output
EXPLANATION
A hash function takes input data and produces a fixed-size output (hash value), useful for hash tables and data indexing.
What will be printed?
String s1 = new String('Amazon');
String s2 = new String('Amazon');
System.out.println(s1 == s2);
A
true
B
false
C
null
D
Error
EXPLANATION
== compares memory references. Both s1 and s2 are different objects, so it prints false. Use .equals() for value comparison.
Which of the following sorting algorithms is most efficient for nearly sorted data?
A
Bubble Sort
B
Quick Sort
C
Insertion Sort
D
Merge Sort
Correct Answer:
C. Insertion Sort
EXPLANATION
Insertion Sort has O(n) time complexity for nearly sorted data, making it the most efficient choice.