the main method overload

Hi all

If the main method can be overloaded so why it doesn't work?
class Passreference{
void pass(){
                Oops7.main(new String[]{"Apple","Windows"});
     Oops7.main(new int[]{10,20});
     }
public class Oops7 {

     public static void main(String[] args) {
System.out.println("String"+"\t"+args);

     }
public static  void main(int x[] ){
     System.out.println("Integer"+"\t"+x);
}
}
The answer is: String [Ljava.lang.String;@addbf1

1. it is not print the values that I'm passing

2. same as if the integer values are passed is gives String [Ljava.lang.String;@addbf1
Why not"Integer java.lan... »

Thanks in advance,
CAT

Popular cat's paw wrote:
Hello

The concept of overload is class that contains the same method but different values of parameter names (it may not of parameters, the type or whatever it is). In this case if she calls only String() (if we as integer values), main method is really overloaded?

The main method can be overloaded Yes, as you did in your code. But the main method is a bit special, so it would be stupid to overload.

Also, no matter how much you surchargerez the main method, hand (String [] args) we're the only one who will be managed by the JAVA virtual machine.

You could test it in this way.

public static void main(String[] args) {
    // This is the entry point to your program _always_
    main(new int[] {1, 2, 3});
    main(1, "string");
}
public static void main(int[] args) {
    System.out.println("I got integers.");
}
public static void main(int i, String s) {
    System.out.println("I have an integer and a String");
}

Tags: Java

Similar Questions

  • Display a message in the main method.

    Someone knows how to display a message in a dialog of the main method (before the creation of the Application object)? It is a background application is not possible to put the message on a screen.

    You can use Ui.getUiEngine () .pushGlobalScreen () to display a screen for a user interface application.

  • Where and how the main method should be defined

    Hi all

    I am new to Java and learning of the http://docs.oracle.com.
    Can someone help me underneath program where and how define a main method.

    public enum {costume
    DIAMONDS,
    CLUBS,
    HEARTS,
    SPADES
    }

    public enum {rank
    TWO, THREE, FOUR, FIVE, SIX, SEVEN,
    EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE
    }

    public class {Card3
    private rank final rank.
    final civil suit;

    Public Card3 (highest rank, suit suit) {}
    This.Rank = grade;
    This.suit = suit;
    }

    public getSuit() {} costume
    return of costume;
    }

    {public getRank() rank
    return of rank;
    }

    public String toString() {}
    return rank + 'of' + costume;
    }
    }

    MPort Java.util;

    public class Deck3 {}
    private static Card3 [] cards = Card3 News [52];
    public Deck3() {}
    int i = 0;
    {for (costume costume: {Suit.values ())}
    {for (the highest ranking: {Rank.values ())}
    maps [i ++] = new Card3 (rank, suit);
    }
    }
    }
    }

    Thank you
    Rambeau

    Hello

    When you are developing a Java application, that you must only have a class with a Main method, other classes do not need that method, the purpose of this methos is that it defines the beginning of your program, look at this link, it is an example and this explains also the Main method:

     http://docs.oracle.com/javase/tutorial/getStarted/application/index.html 
    

    Concerning
    Carlos

  • Impression before the main method

    Hi all
    Class Demo
    {
    
    ///some code........
    
    public static void main(String[] a)
    {
    sop("Inside main");
    
    ///Some code
    
    }}
    Please let me know is possible to print anything before executing the first instruction in the main method. For example, in above cases it is possible to print anything before main interior is printed?

    Kind regards

    Published by: J2EE_Life on January 23, 2012 15:36

    J2EE_Life wrote:
    Please let me know is possible to print anything before executing the first instruction in the main method. For example, in above cases it is possible to print anything before main interior is printed?

    Yes - in a initialize static.

  • args in the main() method

    This might be a complex question. I hope someone can give me a simple answer. I want to know what this code means?
    public static void main(String[] args){
         if(args > 2.length){
         // ect...
    I understand that the main() method creates an array of strings.
    How the table get filled?
    What are filling up with?
    Principal is the starting point for the program and if this table String whence?
    How a table can be created before the program begins?

    SquareBox wrote:
    This might be a complex question. I hope someone can give me a simple answer. I want to know what this code means?

    public static void main(String[] args){
    if(args > 2.length){
    // ect...
    

    Next time, copy and paste, rather than re - type. That does not even compile. Probably you meant

    if (args.length > 2)
    

    I understand that the main() method creates an array of strings.

    N °

    He receives a reference to an array of strings as a parameter. As with any other method receives its parameters. The table is created before the method is called. There is nothing special about main() as Java language is concerned. It's only the JVM that attaches special significance to it.

    How the table get filled?

    The JVM it fills arguments it receives from the OS/shell on the command line before you call your main() method.

    When you run

    java ABC 123 MyClass
    

    the java executable is called, and the operating system will go "ABC", "123" and "MyClass" to her shell. (In fact, I think that it can also pass "java", but whatever). The JVM then load MyClass, creates an array of strings containing "ABC" and "123", and the call of the main() method of MyClass by passing a reference to this String [].

    What are filling up with?

    See above.

    Principal is the starting point for the program and if this table String whence?

    See above.

    How a table can be created before the program begins?

    main() is the starting point for your application that runs inside the JAVA virtual machine. It is not the starting point for the JAVA virtual machine, the shell or the operating system, working together create this table and deliver a reference to it in your main() method.

  • How can I connect to AD with my Recon planner via the main method?

    Hello

    I want to have a main method in my recon scheduler.from here, I want to connect to Ad?
    How can I do this?

    I gave you a few lines of code in your other post. He made the connection with AD. Now, you can use the ctx and make your query which will fetch users etc. of pub for you.

  • Define the main class in the project

    Hi, I have a project in Eclipse with several main methods as I test different things. My question is: How can I change the main method of the project? Because Eclipse is still running the same major and I want to run the code using different network. Thank you

    Greetings.

    For the record, make sure you have only one main method that serve as the entry point for the application.

    But like you said that your goal is now to make a quick test, do a right-click on the class that contains the entry point (main method) you want to test, click on run as-> Blackberry Simulator.

    Make sure that the class you are testing extends the request or UiApplication in order to run it. Otherwise, this entry point will be useless at all.

    In case you want to define an entry point for the project, just delete all the alternative entry points (main methods).

    Good luck. I hope this helps.

  • Urbanship autostartup main method does not

    Hi friends,

    I use urbanship push notification they gave the following code to the main method.

    To autostartup.

    I use jde 6.0

    I followed the step project > properties > Application tab > checked Autostart (box) and module system.

    but my (if) statements of autostartup does not.

    Public Shared Sub main (String [] args) {}
    UrbanAirshipMain nd = new UrbanAirshipMain();

    If (args.length > 0 & args [0] .equals ('autostartup'))

    {

    Application push registry

    nd.registerPushApplication ();

    Create a background process on restarting the device, not user interface

    nd.enterEventDispatcher ();

    }

    on the other

    {

    DISP lay User Interface starts in the foreground

    nd.showGUI ();

    }

    }

    can someone help me. Thanks in advance...

    Kind regards

    Sirot

    You actually spend "autostartup' as a parameter?

    Try a trace here to know what really comes as an argument.

  • Question of the main application class

    Hey people out there!

    A happy Friday to all just a quick question. The class that contains the main Sub public static in the BlackBerry application method, this class should be one that extends UiApplication or can the main method call the class that is responsible for this?

    Thank you!

    Schalk

    You can try something like that.

    class Test
    {
        public static void main(String args[])
        {
            Xyz xyz = new Xyz();
            xyz.enterEventDispatcher();
        }
    }
    ---------------------
    
    class Xyz extends UiApplication
    {
        Xyz()
        {
            pushScreen(new MainScreen());
        }
    }
    
  • java program have main method

    java program have main method

    I note that this issue is still marked as "no response." Not sure if this is due to inactivity during the holiday season, or if there is still confusion. Let me throw in an another wrinkle: If the JAVA virtual machine requires a main() method to launch a program, your code may or may not be liable for this method. In a single normal stand, application of line control, Yes, you do have to provide a main method. But there are other common scenarios where you do not have. If any of these scenarios apply to you, don't waste time searching through the code to the main method, because you won't find it.

    1. web Applications. They often run under a servlet that calls / invokes the application to manage applications for individual customers (e.g. Wicket). In this scenario, the Web application acts as a "listener". (To complicate things even more, the servlet runs inside a parent container, such as Tomcat). The bottom line is, however, that your application itself will have a main() method. Because of some top-level code.

    2. parent controllers. Some frameworks (Spring Batch comes to mind) provide the main method and call the individual portions of your code to execute the steps, tasks, etc. In this scenario, you will not see a main() method, because it is "hidden" in the parent layer.

    There are probably other scenarios as well where the location of the main method is not obvious. These are just two of the most common.

  • messages between the main thread and the FX application thread

    I run a thread of the Application of FX for a main thread using Application.launch [described here: {: identifier of the thread = 2530636}]

    I try to have the application thread return information on the main thread, but Application.launch returns void. Is there an easy way to communicate between the main thread and the thread of the Application?

    So far, I googled and found:
    -MOM (Message Oriented Middleware)
    -Sockets

    Thoughts/ideas/examples are appreciated--especially examples ;)--now I try to use Sockets to show/hide the application and data transmission.

    What is the preferred method? Are there others that I did not find (gasp) via Google?

    Dave.

    Published by: cr0ck3t on April 30, 2013 21:04

    Published by: cr0ck3t on April 30, 2013 21:05

    Is there an easy way to get a reference to these objects to both the main thread and the thread of Application FX - called via Application.launch () since the main thread? Or what I need to use Sockets or MOM?

    Not much to do with the concurrent programming is what I would call easy. It looks easy - but it's not.
    You can do kind of what you're describing using Java concurrency constructs without using sockets or a package of Message Oriented Middleware (MOM).
    With the Java concurrency stuff you really implement your own form or MOM light.
    If you have quite an application is complex with many messages of comes and goes, then a sort of package for MOM such as the camel and ActiveMQ (http://camel.apache.org) is useful.
    ---------
    You can find a sample of the various interactions of thread with JavaFX here:
    https://gist.github.com/jewelsea/5500981 "Simulation of dwarf dragons using multiple threads to eat."
    Related code is just demo-ware to try different competitive access facilities and not necessarily a recommended strategy.
    If your curiosity, you can take a look and try to work out what it is, what it does and how it does.
    The main reason followed is that of a blocking queue:
    http://docs.Oracle.com/javase/6/docs/API/Java/util/concurrent/BlockingQueue.html
    ---------
    Note that once you call launch of the main thread, no subsequent statement in the main method will be different until the JavaFX application terminates. If you can't start from the main thread and communicate with the main thread JavaFX application. Instead, you need to spawn another thread (or a set of threads) for communication with the JavaFX application.
    ---------
    But really, in most cases, the best solution with the simultaneity is not care at all (or at least as little as possible). Write everything in JavaFX, use the animation of JavaFX framework to time related things and the simultaneity of JavaFX utilities for when you really need multiple interaction of wire.
    http://docs.Oracle.com/JavaFX/2/threads/jfxpub-threads.htm
    ----------
    For additional assistance, you may be better off describing exactly (i.e. really specific) what you're trying to make in a new question, perhaps with a solution of the sample in a http://sscce.org NBS

  • Question main method in java, please help

    Guys I looked everywhere on the internet and can not understand one of these questions: I would appreciate any help on them. Is the first and most important thing I would like to know, which is static: what is a static int or a static method of hand? Why is this necessary, and what is its role? Could you please give an example? Also, why String [] args is necessary within the parameters of the main method? Is it so that it can run it? Last thing: objects. Where can I learn about them? I know that they are made with the new operator, but do not include their use? Could you explain why they are useful? You can give them values? and how they relate to the operator point? Once these are answered, I will be so happy because I feel like I am actually somewhat familiar. Right now I'm just confused... Thank you so, so much in advance!

    Is the first and most important thing I would like to know, what is static

    "static" means that the element is associated with the class itself rather than an instance: so it is accessible to all instances.

    Could you please give an example?

    public static void main(String[] args)
    

    is an example, but you already knew that. I don't really understand the question.

    Also, why String [] args is necessary within the parameters of the main method?

    'args' receives the arguments that you type on the command line after the class name or jar, depending on how you call the application.

    It is all covered in the documentation, which you should read before you ask more questions.

    Last thing: objects. Where can I learn about them?

    If you don't know about objects you do not learn about them by asking questions on a forum. It's much too big a subject. You get a book.

  • Subvi hangs when it is closed after being called to a main.vi through the calling method asynchronous start

    Hi all

    I have a main.vi that loads successfully a subvi.vi using the x 100 option and Aysnchronous begin to call the method.

    When the Subvi is finished its Executive, the window remains, some controls can be used and it is really suspended. It requires a kill labview.exe solve complete.

    Note: The Subvi is running and closes smoothly by operating directly...

    I put any code in the Subvi to close in a way, because it was opened through the startup Aysnchronous method?

    Tom

    Sorry, I'm a fool, it turns out that the problem is that I had insode of lines, the main and the Sub - VI of the same name!

    Everything is good now

  • How to access the methods and properties of the main document class

    How can I access methods and properties of the class of main document of other classes?
    Can someone give me a clue what I'm doing wrong?

    I use ActionScript3 in Flash CS3 with strict error checking on. I have an application with several custom classes:

    1. the MainMovie class is associated with the document.

    2. the SomeMovieClip class is associated with a movie clip symbol in the library and an instance of the symbol is placed on the main timeline.

    Compilation Flash returns this error message: "1061: call to a method may not set [name of the method here] through a reference with static type flash.display:DisplayObject.".

    I get the same error if I replace the undelined above with this code:

    root.gotoAndStop ("aFrameLabel");


    If I replace the same code simply with:

    trace (root)

    Flash returns [object MainMovie], which tells me that it recognizes the document class.

    However, if I turn the strict error checking, the compilation ends and the movie works as expected in all cases.

    root cast as a movieclip.

  • Go to the list of the results of the main sequence in my plugin...

    Hi guys,.

    OK, first post here, but I'm a little stuck. I am writing a plugin model to generate a custom HTML report (my requirement has a very specific layout for the report, which is not at all compatible with the html reports generated by teststand normally). Anyway. I generated all labview code, I want to make the report in the format I need, but I'm really bad at actually get information of teststand in a way that is easier.

    What I want to do is browse through the list of the results of the main sequence in the callback sequence DUT-Done of the sequence of pluging, which is stored in

    Parameters.MainSequenceResult.TS.SequenceCall.ResultList according to the documentation, but how can I really access it as a table I can go? All I have in my list of parameter is a reference to the parameters. MainSequenceResult, and for the life of me I can't work out what to call this knowledge actually just get it into a format that I can then use to browse in a loop "foreach" to get out of these settings.

    I'm on a windows machine and teststand 2014 7.

    Any help you could give would be really appreciated!

    J

    The list of top level result is: Parameters.MainSequenceResult.TS.SequenceCall.ResultList

    To find it, I dragged Parameters.MainSequenceResult in the Watch window to a breakpoint and developed it until I found the list of results.

    The ResultList is a PropertyObject which is an array of containers, so as the methods GetPropertyObjectByOffset and GetNumElements are going to work on that.

Maybe you are looking for

  • Merger of the header

    How can I Merge three header boxes just for one?

  • Can't play BluRay from PC via HDMI on plasma TV

    Im having a problem playing a bluray to PC via HDMI on the sanyo plasma TV Introduction page of the fine BD functions with the sound, but the actual sound when the movie plays dosent work. Someone at - it ideas

  • How downgrade to XP on Satellite Pro L 300

    I've read conflicting methods of downgrading to XP. This should have been in the manualMy apologies if this has already been addressed elsewhere (I could not find if it is) 1 Vista will automatically set up when you turn on the laptop2. use 'create a

  • If I delete photos from my iphone library can I keep them on my macbook?

    The photos on the macbook app is connected to my phone via icloud, which seems to be the only way to transfer photos to my computer. The problem is that my phone is running out of memory and I need to remove photos from my phone. If I delete the pict

  • L7580 transfer images from memory card

    I put an SD card in my L7580 and screen LCD has written there are 85 pictures and I should check my PC for the choice of what to do, but there is nothing displayed on my PC.  And the Photo Menu on the printer does not have the choice to transfer phot