An interface with no methods is known as?
1.Abstract Interface
2.Marker Interface
3. Empty Interface
4. Functional Interface
Are all methods in an interface abstract?
1.Yes
2.No
Can an interface inherit from a class?
1.Yes
2.No
3.none
Can an interface method be declared as final?
1. Yes
2. No
How many interfaces can a Java class implement?
1.None
2.Only one
3.Two
4.As many as needed
In Java 9, which type of methods can be added to interfaces to share code between methods?
1.Static
2.Private
3.Final
4.Protected
In Java, what is the primary purpose of the Thread class?
1. File handling
2.String operations
3.Network operations
4.Creating and executing threads
What does a Set guarantee?
1.Order
2.No duplicates
3.Both
4.None of the above
What does the Collections class sort() method do?
1.Sorts elements in descending order
2.Sorts elements in ascending order
3. Randomizes the order of elements
4.Removes duplicates
What does the finally block do?
1.Catches any exception
2.Executes whether an exception is thrown or not
3.Executes only when an exception is thrown
4.Executes only when an exception is not thrown
What does the join() method do when called on a thread object?
1.Terminates the thread
2.Pauses the thread
3.Forces the current executing thread to wait until the thread it's called on completes
4.Checks the status of a thread
What does the transient keyword indicate in a Java class?
1.The variable can change over time
2.The variable cannot be serialized
3. The variable is thread-safe
4.The variable is volatile
What is a daemon thread in Java?
1.A thread that monitors and logs other threads
2.A thread that runs continuously in the background
3.A thread that manages memory usage
4.A thread that is part of the Java virtual machine
What is the default access modifier of a method in an interface in Java?
1. private
2.protected
3.public
4.None of the above
What is the key difference between HashSet and TreeSet?
1.HashSet allows duplicates; TreeSet doesn't
2.HashSet is ordered; TreeSet is unordered
3.HashSet is unordered; TreeSet is ordered
4.HashSet is synchronized; TreeSet is not
What is the purpose of the instanceof operator?
1.Multiply instances
2.Compare two object references
3.Check if an object is an instance of a specific class or interface
4.To create a new instance of a class
What will be the initial capacity of an ArrayList if it is created with the no-argument constructor?
1.0
2.5
3.10
4.16
Which class provides a thread-safe implementation of the List interface?
1.ArrayList
2.Vector
3.HashMap
4.LinkedHashMap
Which Collection does not allow null values?
1. ArrayList
2. HashMap
3. Hashtable
4.LinkedList
Which interface provides an alternative to extending the Thread class?
1.Runnable
2.Callable
3.Executor
4.Parallel
Which interface represents a collection of objects in which duplicate values can be stored?
1. List
2. Set
3.Map
4. ListMap
Which interface represents a key-value pair mechanism?
1.List
2.Set
3.Queue
4.Map
Which Java feature helps achieve multiple inheritance?
1.Abstract classes
2. Static methods
3.Interfaces
4. Enums
Which keyword in Java is used for constant variables?
1.const
2.static
3.constant
4.final
Which keyword in Java is used for importing packages into a program?
1. import
2.package
3.include
4. requires
Which keyword is used to create an instance of a class?
1.new
2.return
3.this
4.create
Which keyword is used to declare a class variable?
1. volatile
2.transient
3. static
4.final
Which keyword is used to define a default method in an interface?
1. static
2.default
3.final
4.abstract
Which keyword is used to inherit the properties and methods from another class?
1.import
2.package
3.extends
4.implements
Which keyword is used to manually throw an exception in Java?
1.new
2.throw
3.throws
4.Throwable
Which keyword is used to prevent a class from being inherited?
1.final
2.abstract
3.class
4.extends
Which keyword is used to refer to the current instance of a class?
1.class
2. this
3.instance
4. object
Which List implementation is synchronized?
1. ArrayList
2. ArrayList
3.LinkedList
4.None of the above
Which method can be used to momentarily pause the execution of the current thread?
1. sleep()
2. wait()
3.pause()
4.stop()
Which method is used to check if a Collection is empty?
1. isEmpty()
2.isNull()
3.checkEmpty()
4.hasElements()
Which method is used to insert an object at a specific position in a List?
1.put()
2. set()
3.insert()
4.add()
Which method is used to start the execution of a thread?
1.run()
2.start()
3.execute()
4. go()
Which of the following can be used to create a custom checked exception?
1.Extending the Exception class
2. Extending the Error class
3.Extending the RuntimeException class
4.None of the above
Which of these can be contained in an interface?
1. Abstract methods
2.Constants
3.Default and static methods
4.Default and static methods
Which of these classes is the superclass of all Exception and Error classes?
1.Exception
2.Error
3.Throwable
4.Object
Which of these is a checked exception?
1.NullPointerException
2. ArithmeticException
3.IOException
4. IndexOutOfBoundsException
Which of these is an unchecked exception?
1.ClassNotFoundException
2.SQLException
3.IOException
4. ArithmeticException
Why were default methods introduced in Java 8 interfaces?
1. To provide multiple inheritance
2.To add utility functions
3.To provide backward compatibility with older interface versions
4.For better performance