Can a method be both generic and static in Java?
Yes, but the type parameter should be declared after the 'static' keyword.
Yes, but the type parameter should be declared before the method name.
No, generic methods cannot be static.
Yes, there are no restrictions.
Which method in the String class is used to compare two strings lexicographically ignoring case?
String
equals()
equalsIgnoreCase()
compareToIgnoreCase()
compareTo()
What does the @Retention(RetentionPolicy.SOURCE) declaration signify for a custom annotation?
@Retention(RetentionPolicy.SOURCE)
The annotation is stored in the class file but is not available at runtime.
The annotation is available at runtime via reflection.
The annotation is discarded by the compiler and not included in the class file.
The annotation is only applicable to source code and has no impact on compiled code.
What happens when a generic class is instantiated with a primitive type in Java?
A compile-time error occurs.
A runtime exception is thrown.
It works as expected.
The primitive type is autoboxed to its wrapper class.
Which class in the java.time package represents a date without a time component?
java.time
LocalDate
Instant
ZonedDateTime
LocalDateTime
What does the File.createNewFile() method do if a file with the same name already exists in the specified location?
File.createNewFile()
It overwrites the existing file with an empty file.
It appends a number to the file name to create a unique file.
It throws a FileNotFoundException.
FileNotFoundException
It returns false without creating a new file.
false
Which interface in the Java Collections Framework represents a group of objects where duplicates are not allowed?
Queue
Map
Set
List
Which List implementation in Java uses a dynamic array to store elements and provides fast access to elements by their index?
Stack
LinkedList
ArrayList
Vector
What is the time complexity of retrieving an element from a HashSet in Java, assuming the hash function distributes elements evenly?
O(1)
O(n)
O(n log n)
O(log n)
Can a static inner class access non-static members of its outer class directly?
Yes
No