none
Java

    Question

  • Why the class having main method in java can not be declared as private and protected????/

    Please answer.........


    • Edited by swati shrivastava Thursday, July 18, 2013 2:59 PM
    • Moved by litdev Wednesday, July 24, 2013 6:48 AM From Small Basic
    Thursday, July 18, 2013 2:58 PM

Answers

  • You should ask in a Java forum, as this forum is about Small Basic.

    Jan [ WhTurner ] The Netherlands

    Thursday, July 18, 2013 3:32 PM
  • As you had noticed by now, this forum is about a programming language called Small Basic.

    I believe Java's main() method has to be public b/c it's supposed to be called externally from the Java's runtime itself!

    So, it can't be locked away within its own class. Thus neither private nor protect are allowed for it!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)


    Thursday, July 18, 2013 3:59 PM
  • Although you are in the wrong forum, I will add on to what GoTo loop said. The main() method must be public so that the runtime can find the main entry point for the application. For similar reasons, the method must also be static: so that the JRE can call the main entry point without instantiating anything else: otherwise, the constructor would actually be the main entry point!

    Please mark any answers and "vote as helpful" any posts that help you!

    Thursday, July 18, 2013 7:55 PM

All replies

  • I'm sorry but this is no java forum, it is about the programming language Small Basic.

    about your question, see private-protected-class

    • Proposed as answer by gungan37 Friday, July 19, 2013 1:18 AM
    Thursday, July 18, 2013 3:31 PM
  • You should ask in a Java forum, as this forum is about Small Basic.

    Jan [ WhTurner ] The Netherlands

    Thursday, July 18, 2013 3:32 PM
  • As you had noticed by now, this forum is about a programming language called Small Basic.

    I believe Java's main() method has to be public b/c it's supposed to be called externally from the Java's runtime itself!

    So, it can't be locked away within its own class. Thus neither private nor protect are allowed for it!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)


    Thursday, July 18, 2013 3:59 PM
  • Although you are in the wrong forum, I will add on to what GoTo loop said. The main() method must be public so that the runtime can find the main entry point for the application. For similar reasons, the method must also be static: so that the JRE can call the main entry point without instantiating anything else: otherwise, the constructor would actually be the main entry point!

    Please mark any answers and "vote as helpful" any posts that help you!

    Thursday, July 18, 2013 7:55 PM