Spring Questions and Answers – Introducing Behaviors and States to Your Beans

This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses on “Introducing Behaviors and States to Your Beans”.

1. Which special type of advice is used to implement an interface?
a) Introduction
b) Before
c) After
d) AfterSpecial
View Answer

Answer: a
Explanation: It allows your objects to implement an interface dynamically by providing an implementation class for that interface.

2. Introduction advice helps in implementing multiple inheritance
a) True
b) False
View Answer

Answer: a
Explanation: You are able to introduce multiple interfaces with multiple implementation classes to your objects at the same time.

3. In introduction advice you have to modify class to introduce new methods
a) True
b) False
View Answer

Answer: b
Explanation: You can introduce methods to your existing classes even without source code available.
advertisement
advertisement

4. How does an Introduction advice do this in Spring?
a) dynamic proxy
b) web proxy
c) implements org.springframework.net.bundle interface
d) none of the mentioned
View Answer

Answer: a
Explanation: Introduction works by adding an interface to the dynamic proxy.

5. Annotation used to declare an introduction
a) Before
b) After
c) @DeclareParents
d) None of the mentioned
View Answer

Answer: c
Explanation: In this aspect, you can declare an introduction by annotating an arbitrary field with the @DeclareParents annotation.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Target Classes can be denoted by Introduction Annotation
a) True
b) False
View Answer

Answer: a
Explanation: The value attribute of the @DeclareParents annotation type indicates which classes are the targets for this introduction.

7. Attribute used to specify implementation class
a) no such attribute
b) defaultImpl
c) defaultInterface
d) defaultImplement
View Answer

Answer: b
Explanation: The interface to introduce is determined by the type of the annotated field. Finally, the implementation class used for this new interface is specified in the defaultImpl attribute.
advertisement

8. How to keep track of the usage of your beans
a) Calling Count
b) Last modified date
c) New Interface to your object
d) All of the mentioned
View Answer

Answer: d
Explanation: You can introduce a new interface to your objects with an implementation class that holds the state field.

9. How to introduce counter field to original bean class?
a) Using Spring AOP
b) Implementing interface
c) AspectJ Pointcut
d) None of the mentioned
View Answer

Answer: a
Explanation: Since there is no field for storing the counter value in the original classes, you need to introduce one with Spring AOP.
advertisement

10. Tag used to declare aspects
a) aop:config
b) aop:auto-proxy
c) aop:autowire
d) None of the mentioned
View Answer

Answer: a
Explanation: In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring, 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.