Bird
0
0

Which of the following is true about the main function in Kotlin?

easy📝 Conceptual Q2 of 15
Kotlin - Basics and JVM Runtime
Which of the following is true about the main function in Kotlin?
AIt must always have a return type of Int.
BIt can have parameters to accept command-line arguments.
CIt cannot be declared more than once in a program.
DIt is optional and the program runs without it.
Step-by-Step Solution
Solution:
  1. Step 1: Recall main function signature options

    Kotlin's main can accept parameters like args: Array<String> for command-line arguments.
  2. Step 2: Evaluate each statement

    The statement 'It can have parameters to accept command-line arguments.' is true. 'It must always have a return type of Int.' is false because main returns Unit by default. 'It cannot be declared more than once in a program.' is false as multiple mains can exist in different files. 'It is optional and the program runs without it.' is false because main is required.
  3. Final Answer:

    It can have parameters to accept command-line arguments. -> Option B
  4. Quick Check:

    Main parameters = Command-line args allowed [OK]
Quick Trick: Main can take args to receive command-line inputs [OK]
Common Mistakes:
MISTAKES
  • Assuming main must return Int
  • Believing main is optional
  • Thinking only one main can exist anywhere

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes