JNDI/JNDI MCQ QUESTIONS AND ANSWER Sample Test,Sample questions

Question:
An interface with no methods is known as?

1.Abstract Interface

2.Marker Interface

3. Empty Interface

4. Functional Interface


Question:
Are all methods in an interface abstract?

1.Yes

2.No


Question:
Can an interface inherit from a class?

1.Yes

2.No

3.none


Question:
Can an interface method be declared as final?

1. Yes

2. No


Question:
How many interfaces can a Java class implement?

1.None

2.Only one

3.Two

4.As many as needed


Question:
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


Question:
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


Question:
What does a Set guarantee?

1.Order

2.No duplicates

3.Both

4.None of the above


Question:
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


Question:
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


Question:
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


Question:
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


Question:
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


Question:
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


Question:
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


Question:
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


Question:
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


Question:
Which class provides a thread-safe implementation of the List interface?

1.ArrayList

2.Vector

3.HashMap

4.LinkedHashMap


Question:
Which Collection does not allow null values?

1. ArrayList

2. HashMap

3. Hashtable

4.LinkedList


Question:
Which interface provides an alternative to extending the Thread class?

1.Runnable

2.Callable

3.Executor

4.Parallel


Question:
Which interface represents a collection of objects in which duplicate values can be stored?

1. List

2. Set

3.Map

4. ListMap


Question:
Which interface represents a key-value pair mechanism?

1.List

2.Set

3.Queue

4.Map


Question:
Which Java feature helps achieve multiple inheritance?

1.Abstract classes

2. Static methods

3.Interfaces

4. Enums


Question:
Which Java feature helps achieve multiple inheritance?

1.Abstract classes

2. Static methods

3.Interfaces

4. Enums


Question:
Which keyword in Java is used for constant variables?

1.const

2.static

3.constant

4.final


Question:
Which keyword in Java is used for importing packages into a program?

1. import

2.package

3.include

4. requires


Question:
Which keyword is used to create an instance of a class?

1.new

2.return

3.this

4.create


Question:
Which keyword is used to declare a class variable?

1. volatile

2.transient

3. static

4.final


Question:
Which keyword is used to define a default method in an interface?

1. static

2.default

3.final

4.abstract


Question:
Which keyword is used to inherit the properties and methods from another class?

1.import

2.package

3.extends

4.implements


Question:
Which keyword is used to manually throw an exception in Java?

1.new

2.throw

3.throws

4.Throwable


Question:
Which keyword is used to prevent a class from being inherited?

1.final

2.abstract

3.class

4.extends


Question:
Which keyword is used to refer to the current instance of a class?

1.class

2. this

3.instance

4. object


Question:
Which List implementation is synchronized?

1. ArrayList

2. ArrayList

3.LinkedList

4.None of the above


Question:
Which method can be used to momentarily pause the execution of the current thread?

1. sleep()

2. wait()

3.pause()

4.stop()


Question:
Which method is used to check if a Collection is empty?

1. isEmpty()

2.isNull()

3.checkEmpty()

4.hasElements()


Question:
Which method is used to insert an object at a specific position in a List?

1.put()

2. set()

3.insert()

4.add()


Question:
Which method is used to start the execution of a thread?

1.run()

2.start()

3.execute()

4. go()


Question:
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


Question:
Which of these can be contained in an interface?

1. Abstract methods

2.Constants

3.Default and static methods

4.Default and static methods


Question:
Which of these classes is the superclass of all Exception and Error classes?

1.Exception

2.Error

3.Throwable

4.Object


Question:
Which of these is a checked exception?

1.NullPointerException

2. ArithmeticException

3.IOException

4. IndexOutOfBoundsException


Question:
Which of these is an unchecked exception?

1.ClassNotFoundException

2.SQLException

3.IOException

4. ArithmeticException


Question:
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


Question:
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


More MCQS

  1. JNDI MCQ QUESTIONS AND ANSWER
  2. JNDI MCQ QUESTIONS AND ANSWER
  3. JNDI MCQ QUESTIONS AND ANSWER
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!