Bird
0
0

Given this code snippet, what will be the output when running the Spring Boot application?

medium📝 component behavior Q4 of 15
Spring Boot - Spring Annotations
Given this code snippet, what will be the output when running the Spring Boot application?
@SpringBootApplication
public class DemoApp {
  public static void main(String[] args) {
    System.out.println("Starting app...");
    SpringApplication.run(DemoApp.class, args);
  }
}
APrints nothing and starts the application
BPrints "Starting app..." but does not start the application
CThrows a runtime error due to missing @EnableAutoConfiguration
DPrints "Starting app..." and starts the Spring Boot application
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the main method behavior

    The main method prints "Starting app..." before calling SpringApplication.run.
  2. Step 2: Understand @SpringBootApplication effect

    This annotation enables auto-configuration and component scanning, so the application starts normally.
  3. Final Answer:

    Prints "Starting app..." and starts the Spring Boot application -> Option D
  4. Quick Check:

    Prints message then runs app due to @SpringBootApplication [OK]
Quick Trick: Code before SpringApplication.run executes normally [OK]
Common Mistakes:
  • Assuming missing @EnableAutoConfiguration causes error
  • Thinking print statement is skipped
  • Believing app does not start without extra config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes