QuizzesBean Lifecycle & Scope — Concept Check
intermediate
spring-boot

Bean Lifecycle & Scope — Concept Check

Questions on Bean Lifecycle & Scope. Spring manages beans through a well-defined lifecycle; scopes (singleton, prototype, request, session) determine how many instances are created and when they are destroyed.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Bean Lifecycle & Scope — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer notices that their Spring bean's @PreDestroy method is not being called. The bean is scoped as 'prototype'. What is the reason?

    • A@PreDestroy is not called for prototype beans
    • B@PreDestroy is only called for singleton beans
    • CThe bean is not properly configured
    • DThe application context is not shutting down
  2. 2.A Spring application has a CacheService bean implementing InitializingBean. When is the init() method called?

    • ADuring the bean's instantiation
    • BAfter all dependencies are injected
    • CAfter the bean is destroyed
    • DBefore the constructor is called
  3. 3.You have a singleton-scoped bean that needs to access a request-scoped bean. How should you configure this?

    • ADirectly inject the request-scoped bean
    • BUse a static method to access the request bean
    • CUse a scoped proxy for the request-scoped bean
    • DChange the singleton bean to request scope
  4. 4.A developer uses @PostConstruct and InitializingBean in the same bean. What happens?

    • ABoth methods run, but order is not guaranteed
    • BNeither method runs
    • COnly InitializingBean runs
    • DOnly @PostConstruct runs
  5. 5.In a Spring application, a bean implements BeanPostProcessor. What can it do?

    • AManage bean destruction
    • BHandle HTTP requests
    • CManage database connections
    • DIntercept and transform beans during initialization
  6. 6.A developer claims that singleton beans are thread-safe by default in Spring. Is this true?

    • AOnly if @Synchronized is used
    • BOnly if the bean is stateless
    • CYes, Spring ensures thread safety
    • DNo, thread safety is the developer's responsibility
  7. 7.What happens if a bean implements both BeanNameAware and BeanFactoryAware interfaces?

    • AIt only receives the BeanFactory
    • BIt receives both the bean name and BeanFactory
    • CIt only receives the bean name
    • DIt receives neither
  8. 8.A developer configures a bean with @Scope("prototype") but notices it behaves like a singleton. What might be wrong?

    • AThe bean's constructor is private
    • BThe bean is incorrectly annotated
    • CThe application context is misconfigured
    • DThe bean is injected into a singleton without a proxy