Olete.in
Articles
Mock Tests
🧪 Spring MCQ Quiz Hub
Spring Mcq Set 1
Choose a topic to test your knowledge and improve your Spring skills
1. Beans can be created by which of the following properties?
Scope
Property
Class
It’s own constructor
2. Which attribute is used to specify class name of the bean?
name
id
class
constructor-args
3. Which of the following method can be used to used to instantiate a method?
static factory method
default-init method
destroy method
lazy-init method
4. Which attribute is used to specify static factory-method?
factory-method
default-init method
destroy method
lazy-init method
5. Purpose of Static Factory Method?
Static method to create an object
Initialize bean
All of the mentioned
None of the mentioned
6. Exception thrown by factory method?
IllegalArgumentException
IndexOutofBoundException
ClassPathNotFoundException
BeanCreationException
7. What will be the output? Snippet of Code: public class CreatePro { String ProductId; public CreatePro(String ProductId) { this.ProductId = ProductId; } public static Product creation_Product(String productId) { System.out.println("Bean Created"); if ("aaa".equals(productId)) { return new Battery("AAA", 2.5); } else if ("cdrw".equals(productId)) { return new Disc("CD-RW", 1.5); } } } <beans ...> <bean id="aaa" class="CreatePro" factory-method="createProduct"> <constructor-arg value="aaa" /> </bean> <bean id="cdrw" class="CreatePro" factory-method="createProduct"> <constructor-arg value="cdrw" /> </bean> </beans>
BeanCreationException
Bean Created
ClassPathException
none of the mentioned
8. Beans can be created by which of the following properties?
Static factory-method
Instance Factory-Method
All of the mentioned
none of the mentioned
9. Bean’s naming convention:- starts with lowercase, camelcase from then on.?
True
False
None
all of the mentioned
10. A bean can have more than one name using multiple id attributes?
True
False
error
None of these
11. The bean instance is mentioned by the factory-method attribute, while the factory method is signified by the factory-bean attribute?
True
False
error
None of these
12. One factory class can also hold more than one factory method True/False?
True
False
None
all of the mentioned
13. Instance Factory method main purpose is to encapsulate the object-creation process in a method of another object instance.
True
False
error
all of the mentioned
14. Which Attribute is used to specify the bean declared?
factory-bean
scope
getBean
declareBean
15. Declaring Beans using:-
Static field
Object Properties
All of the mentioned
none of the mentioned
16. Ways to declare bean from a static field?
FieldRetrievingFactoryBean
util:contant
All of the mentioned
none of the mentioned
17. Declaring a bean from a static field requires a built-in factory bean FieldRetrievingFactoryBean and fully qualified field name or instance field is specified in the list property.
True
False
error
none of the mentioned
18. . A) public abstract class Product { public static final Product AAA = new Battery("AAA", 2.5); public static final Product CDRW = new Disc("CD-RW", 1.5); ... } <beans ...> <bean id="aaa" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean"> <property name="staticField"> <value>com.shop.Product.AAA</value> </property> </bean> <bean id="cdrw" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean"> <property> name="staticField" valuecom.shop.Product.CDRW/value </property> </bean> </beans> B) Product aaa = com.shop.Product.AAA; Product cdrw = com.shop.Product.CDRW;
A and B are equivalent
A and B provides different functionality
Runtime Error in A
Exception in B
19. Is this bean configuration metadata correct? <beans ...> bean id="com.shop.Product.AAA" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean" / bean id="com.shop.Product.CDRW" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean" / </beans>
Yes
No
error
None of these
20. Which tag is also allowed by static field?
util:constant
list
set
constructor-args
21. Is this bean configuration correct? <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util/spring-util-3.0.xsd" util:constant id="aaa" static-field="com.shop.Product.AAA" /> util:constant id="cdrw" static-field="com.shop.Product.CDRW" /> </beans>
Yes
No
error
None of these
22. Declaring bean form object properties can be done using:-
PropertyPathFactoryBean
util:constant
None of the mentioned
all of the mentioned
23. Inner Bean can be retrieved by it’s name.
True
False
error
None of these
24. PropertyPathFactoryBean declares a bean from an:-
Object Property
Property Path
All of the mentioned
none of the mentioned
25. The propertyPath property of PropertyPathFactoryBean can accept only a single property name.
True
False
error
None of these
26. Alternate way of PropertyPathFactoryBean to declare a bean.
util:property-path tag
util:constant tag
None of the mentioned
all of the mentioned
27. We can combine target Object and propertyPath properties as bean name/id of PropertyPathFactoryBean.
True
False
error
None of these
28. The Spring Expression Language can be accessed by:-
XML configuration
Annotations
None of the mentioned
All of the mentioned
29. A bean can be requested by:-
getBean method
reference from another bean using autowiring, property etc
all of the mentioned
none of the mentioned
30. Which attribute is used to set the scope of the bean?
setScope
scope
getScope
none of the mentioned
31. Which one is the default scope of the beans?
Prototype
Session
Request
Singleton
32. Which scope creates a new bean instance each time when requested?
Singleton
Prototype
Session
Request
33. Which of the following are considered valid beans?
Singleton
Prototype
All of the mentioned
none of the mentioned
34. In above question if scope of shoppingCart named bean is prototype, then what will be the output? What will be the output?
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)
Shopping cart 1 contains (AAA 2.5, CD-RW 1.5) Shopping cart 2 contains (DVD-RW 3.0)
BeanCreationException
none of the mentioned
35. Which interface is used to perform initialization of beans?
InitializingBean
Disposablebean
None of the mentioned
all of the mentioned
36. Which interface is used to perform destruction of beans?
InitializingBean
Disposablebean
None of the mentioned
all of the mentioned
37. Alternate way of initialization method is:-
init-method attribute
afterPropertiesSet
destroy-method attribute
none of the mentioned
38. Alternate way of destruction method is:-
init-method attribute
afterPropertiesSet
destroy-method attribute
none of the mentioned
39. Which annotation is used as a substitute of initialization method?
@PostConstruct
@PreDestroy
None of the mentioned
all of the mentioned
40. Which annotation is used as a substitute of destroy method?
@PostConstruct
@PreDestroy
None of the mentioned
All of the mentioned
41. Which configuration can be used for Dependency Injection?
XML Configuration
Annotation Configuration
Java Based Configuration
All of the mentioned
42. Method used to process bean before initialization callback
scope
postProcessAfterInitialization()
postProcessBeforeInitialization()
it’s own constructor
43. Method used to process bean after initialization callback
scope
getBean
postProcessAfterInitialization()
it’s own constructor
44. Which method is used to gracefully shutdown all the bean processes after closing the spring container?
shutdownHook
destroy method
none of the mentioned
all of the mentioned
45. Which method is used to register BeanPostProcessor?
addBeanPostProcessors
registerBeanPostProcessors
addBeanProcessors
none of the mentioned
46. Which Interface for bean Post Processor is used to distinguish between checked beans
StorageConfig
Marker
None of the mentioned
all of the mentioned
47. Which method of bean post processors is used to check path existence
getPath
setPath
value
auto-wiring
48. PathCheckingBeanPostProcessor will not work properly in case of:-
XML Configuration
Java based Configuration
JSR Annotation
none of the mentioned
49. Which bean factory post processor externalizes part of the bean configurations into a properties file
PropertyPlaceholderConfigurer
PropertyPlaceholderRegister
PropertyGetPath
None of the mentioned
50. Which interface defines methods for resolving text messages
MessageSource
ApplicationListener
ApplicationContextListener
TextEvent
Submit