Results 1 to 5 of 5
  1. #1
    dienesh77 is offline Member
    Join Date
    Feb 2011
    Posts
    32
    Rep Power
    0

    Default 2 methods with same name Question

    import javax.swing.*;
    public class Duplicate {

    /**
    * @param args
    */
    public static void methd(){
    javax.swing.JOptionPane.showMessageDialog(null, "How I wonder what you are");
    }
    public static void main(String[] args) {
    JOptionPane.showMessageDialog(null, "Twinkle Twinkle Little Star");
    methd ();

    }
    public static void main() {
    javax.swing.JOptionPane.showMessageDialog(null, "How I wonder what you are");
    }

    }


    Why does the program compiles without errors despite the fact that it contains two methods with the same name main?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dienesh77 View Post
    Why does the program compiles without errors despite the fact that it contains two methods with the same name main?
    Their names might be the same but their argument lists differ; those are overloaded methods.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by dienesh77 View Post
    Why does the program compiles without errors despite the fact that it contains two methods with the same name main?
    Don't you think the parameters of both the main methods are different? One takes a String array and another takes nothing.

    They have the same name, but they are not the same.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    For more details: Java Methods

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    dienesh77,

    Don't you know about function overloading or method overloading(JAVA) ?

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  3. Replies: 4
    Last Post: 04-03-2009, 06:36 AM
  4. Newbie question about Static methods
    By SCS17 in forum New To Java
    Replies: 9
    Last Post: 02-06-2008, 08:03 AM
  5. question about abstract methods
    By osval in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:36 PM

Posting Permissions

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