Test Series - spring

Test Number 3/20

Q: A bean can be requested by:-
A. getBean method
B. reference from another bean using autowiring, property etc
C. all of the mentioned
D. none of the mentioned
Solution: When a bean is requested by the getBean() method or a reference from other beans, Spring will decide which bean instance should be returned according to the bean scope.
Q: Which attribute is used to set the scope of the bean?
A. setScope
B. scope
C. getScope
D. none of the mentioned
Solution: Scope attribute defines the scope of a bean.
Q: Which one is the default scope of the beans?
A. Prototype
B. Session
C. Request
D. Singleton
Solution: This unique bean instance will be returned for all subsequent getBean() calls and bean references.
Q: Which scope creates a new bean instance each time when requested?
A. Singleton
B. Prototype
C. Session
D. Request
Solution: Creates a new bean instance each time when requested.
Q: Which of the following are considered valid beans?
A. Singleton
B. Prototype
C. All of the mentioned
D. None of the mentioned
Solution: In Spring 1.x, singleton and prototype are the only two valid bean scopes, and they are specified by the singleton attribute (i.e., singleton=”true” or singleton=”false”), not the scope attribute.
Q: In above question if scope of shoppingCart named bean is prototype, then what will be the output?
What will be the output?
A. Shopping cart 1 contains (AAA 2.5, CD-RW 1.5) Shopping cart 2 contains (AAA 2.5, CD-RW 1.5, DVD-RW 3.0)
B. Shopping cart 1 contains (AAA 2.5, CD-RW 1.5) Shopping cart 2 contains (DVD-RW 3.0)
C. BeanCreationException
D. None of the mentioned
Solution: Since the default scope is prototype, so items added by first bean instantiated will be removed by same bean if instantiated again, and will add new items listed.
Q: Which interface is used to perform initialization of beans?
A. InitializingBean
B. Disposablebean
C. None of the mentioned
D. All of the mentioned
Solution: Spring allows your bean to perform initialization callback methods afterPropertiesSet() by implementing the InitializingBean and interfaces.
Q: Which interface is used to perform destruction of beans?
A. InitializingBean
B. Disposablebean
C. None of the mentioned
D. All of the mentioned
Solution: Spring allows your bean to perform destroy callback methods destroy() by implementing the DisposableBean and interfaces.
Q: Alternate way of initialization method is:-
A. init-method attribute
B. afterPropertiesSet
C. destroy-method attribute
D. none of the mentioned
Solution: A better approach of specifying the initialization callback methods is by setting the init-method attributes in your bean declaration.
Q: Which configuration can be used for Dependency Injection?
A. XML Configuration
B. Annotation Configuration
C. Java Based Configuration
D. All of the mentioned
Solution: All of the above mentioned can be used for Dependency Injection.

You Have Score    /10