Advanced 250+ TOP MCQs on Annotations and Answers

This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “Annotations”.

1. Which version of Java introduced annotation?
a) Java 5
b) Java 6
c) Java 7
d) Java 8

Answer: a
Clarification: Annotation were introduced with Java 5 version.

2. Annotation type definition looks similar to which of the following?
a) Method
b) Class
c) Interface
d) Field

Answer: c
Clarification: Annotation type definition is similar to an interface definition in which the keyword interface is preceded by the sign @.

3. Which of the following is not pre defined annotation in Java?
a) @Deprecated
b) @Overriden
c) @SafeVarags
d) @FunctionInterface

Answer: b
Clarification: @Overriden is not a pre defined annotation in Java. @Depricated, @Override, @SuppressWarnings, @SafeVarags and @FunctionInterface are the pre defined annotations.

4. Annotations which are applied to other annotations are called meta annotations.
a) True
b) False

Answer: a
Clarification: Annotations which are applied to other annotations are called meta annotations.

5. Which one of the following annotations is not used in Hibernate?
a) @Entity
b) @Column
c) @Basic
d) @Query

Answer: d
Clarification: @Query is not an annotation used in Hibernate.

6. Which one of the following is not ID generating strategy using @GeneratedValue annotation?
a) Auto
b) Manual
c) Identity
d) Sequence

Answer: b
Clarification: Auto, Table, Identity and Sequence are the ID generating strategies using @GeneratedValue annotation.

7. Which one of the following is not an annotation used by Junit with Junit4?
a) @Test
b) @BeforeClass
c) @AfterClass
d) @Ignored

Answer: d
Clarification: @Test, @Before, @BeforeClass, @After, @AfterClass and @Ignores are the annotations used by Junit with Junit4.

8. Using which annotation non visible or private method can be tested?
a) @VisibleForTesting
b) @NonVisibleForTesting
c) @Visible
d) @NonVisible

Answer: a
Clarification: Using @VisibleForTesting annotation private or non visible method can be tested.

9. Which of the following annotation is used to avoid execution of Junits?
a) @NoTest
b) @explicit
c) @avoid
d) @ignore

Answer: d
Clarification: @ignore annotation is used to avoid execution of Junits.

10. Which is the Parent class of annotation class?
a) Class
b) Object
c) Main
d) Super

Answer: b
Clarification: Object is the parent class of annotation class.

Leave a Reply

Your email address will not be published. Required fields are marked *