250+ TOP MCQs on Introducing Behaviors and States to Your Beans and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: You can introduce methods to your existing classes even without source code available.

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
Answer: a
Clarification: 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
Answer: c
Clarification: In this aspect, you can declare an introduction by annotating an arbitrary field with the @DeclareParents annotation.

6. Target Classes can be denoted by Introduction Annotation
a) True
b) False
Answer: a
Clarification: 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
Answer: b
Clarification: 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.

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
Answer: d
Clarification: 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
Answer: a
Clarification: Since there is no field for storing the counter value in the original classes, you need to introduce one with Spring AOP.

10. Tag used to declare aspects
a) aop:config
b) aop:auto-proxy
c) aop:autowire
d) None of the mentioned
Answer: a
Clarification: In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.

Leave a Reply

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