This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “Annotations”.
1. Which version of Java introduced annotation? Answer: a 2. Annotation type definition looks similar to which of the following? Answer: c 3. Which of the following is not pre defined annotation in Java? Answer: b 4. Annotations which are applied to other annotations are called meta annotations. Answer: a 5. Which one of the following annotations is not used in Hibernate? Answer: d 6. Which one of the following is not ID generating strategy using @GeneratedValue annotation? Answer: b 7. Which one of the following is not an annotation used by Junit with Junit4? Answer: d 8. Using which annotation non visible or private method can be tested? Answer: a 9. Which of the following annotation is used to avoid execution of Junits? Answer: d 10. Which is the Parent class of annotation class? Answer: b
a) Java 5
b) Java 6
c) Java 7
d) Java 8
Clarification: Annotation were introduced with Java 5 version.
a) Method
b) Class
c) Interface
d) Field
Clarification: Annotation type definition is similar to an interface definition in which the keyword interface is preceded by the sign @.
a) @Deprecated
b) @Overriden
c) @SafeVarags
d) @FunctionInterface
Clarification: @Overriden is not a pre defined annotation in Java. @Depricated, @Override, @SuppressWarnings, @SafeVarags and @FunctionInterface are the pre defined annotations.
a) True
b) False
Clarification: Annotations which are applied to other annotations are called meta annotations.
a) @Entity
b) @Column
c) @Basic
d) @Query
Clarification: @Query is not an annotation used in Hibernate.
a) Auto
b) Manual
c) Identity
d) Sequence
Clarification: Auto, Table, Identity and Sequence are the ID generating strategies using @GeneratedValue annotation.
a) @Test
b) @BeforeClass
c) @AfterClass
d) @Ignored
Clarification: @Test, @Before, @BeforeClass, @After, @AfterClass and @Ignores are the annotations used by Junit with Junit4.
a) @VisibleForTesting
b) @NonVisibleForTesting
c) @Visible
d) @NonVisible
Clarification: Using @VisibleForTesting annotation private or non visible method can be tested.
a) @NoTest
b) @explicit
c) @avoid
d) @ignore
Clarification: @ignore annotation is used to avoid execution of Junits.
a) Class
b) Object
c) Main
d) Super
Clarification: Object is the parent class of annotation class.