Bird
0
0

Given this file structure:

medium📝 Predict Output Q5 of 15
Java - Packages and Access Control
Given this file structure:
src/com/app/Main.java

and Main.java starts with package com.app;, what happens if you try to run java Main from src?
AError: Could not find or load main class Main
BProgram runs successfully
CError: Package not declared
DProgram runs but prints nothing
Step-by-Step Solution
Solution:
  1. Step 1: Understand package and running command

    The class is in package com.app, so it must be run with full package name.
  2. Step 2: Running java Main from src ignores package, causing error

    You must run java com.app.Main from src or set classpath properly.
  3. Final Answer:

    Error: Could not find or load main class Main -> Option A
  4. Quick Check:

    Run with full package name to avoid error [OK]
Quick Trick: Run classes with full package name, not just class name [OK]
Common Mistakes:
  • Running class without package prefix
  • Ignoring folder structure for packages
  • Expecting no error without correct command

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes