Results 1 to 7 of 7
  1. #1
    Z.S.Tehrani is offline Member
    Join Date
    Jul 2008
    Posts
    14
    Rep Power
    0

    Default the method "main"

    which class the method "main" belongs to ? and how java behaves with the method "main" ?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please see multiple answers to your same question / cross-post in the Sun Java forums.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Z.S.Tehrani View Post
    which class the method "main" belongs to ? and how java behaves with the method "main" ?
    In simple world, each class have a main method. That's the first method which JVM execute. Mainmethod executes are other methods as needed.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    The method "main" belongs to every class which has one. There is nothing special about the main method. The only thing that sets the "main" method apart from any other static method, is that when say

    [code]
    java MyClass
    [/class]

    the jvm will attempt to invoke the static method main with a String[] as the argument. So, if that method does not exist, the JVM cannot start your program, but for all of that, it is still just another static method.

  5. #5
    Z.S.Tehrani is offline Member
    Join Date
    Jul 2008
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    The method "main" belongs to every class which has one. There is nothing special about the main method. The only thing that sets the "main" method apart from any other static method, is that when say

    [code]
    java MyClass
    [/class]

    the jvm will attempt to invoke the static method main with a String[] as the argument. So, if that method does not exist, the JVM cannot start your program, but for all of that, it is still just another static method.
    Thanks for the answer

  6. #6
    Z.S.Tehrani is offline Member
    Join Date
    Jul 2008
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    In simple world, each class have a main method. That's the first method which JVM execute. Mainmethod executes are other methods as needed.
    Thanks for your answer

  7. #7
    Z.S.Tehrani is offline Member
    Join Date
    Jul 2008
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Please see multiple answers to your same question / cross-post in the Sun Java forums.
    Ok,thanks and sorry for posting a repeated thread

Similar Threads

  1. Replies: 5
    Last Post: 05-14-2008, 02:43 PM
  2. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  3. Replies: 1
    Last Post: 07-27-2007, 11:59 PM
  4. Replies: 1
    Last Post: 07-25-2007, 11:55 PM
  5. Replies: 1
    Last Post: 07-16-2007, 07:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •