Advanced Java Questions & Answers – Annotations

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

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

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

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

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

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: @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
View Answer

Answer: b
Explanation: 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
View Answer

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

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

Answer: a
Explanation: 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
View Answer

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

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

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

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.