1.

Which of these access specifiers must be used for main() method?(a) private(b) public(c) protected(d) none of the mentionedI had been asked this question at a job interview.I want to ask this question from Access Control topic in division Classes and Methods of Java

Answer»

The correct CHOICE is (b) public

Easiest explanation: main() method must be specified public as it called by Java run time system, OUTSIDE of the program. If no ACCESS SPECIFIER is used then by default member is public within its own package & cannot be accessed by Java run time system.



Discussion

No Comment Found

Related InterviewSolutions