How the object of main class is created?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How the object of main class is created?

  1. #1
    Patel V D Guest

    How the object of main class is created?


    Hi All,
    I have recently started JAVA prgramming.I am confused with the way java
    handles the creation of object of main class of the program.I mean how and
    when the object of the main class(Which is the name of the .java file itself)
    is created.
    for example,consider the simple program structure
    class temp
    {
    public static void main(String args[])
    {
    //some code
    }
    }
    Now,how and when the JAVA creates the object of class temp.

    Looking forward for reply.
    Thank you.
    -Vikas.

  2. #2
    Jason Bock Guest

    Re: How the object of main class is created?

    A temp object is never created. Since you're calling a static method on
    temp, you'll never get a temp object.

    HTH,

    Jason

    "Patel V D" <patel_vikasp@hotmail.com> wrote in message
    news:38f3677b$1@news.devx.com...
    >
    > Hi All,
    > I have recently started JAVA prgramming.I am confused with the way java
    > handles the creation of object of main class of the program.I mean how and
    > when the object of the main class(Which is the name of the .java file

    itself)
    > is created.
    > for example,consider the simple program structure
    > class temp
    > {
    > public static void main(String args[])
    > {
    > file://some code
    > }
    > }
    > Now,how and when the JAVA creates the object of class temp.
    >
    > Looking forward for reply.
    > Thank you.
    > -Vikas.




  3. #3
    Tom Duffy Guest

    Re: How the object of main class is created?


    Hello Patel:

    The main() method is called automatically by the JVM. If you choose to create
    an object of type temp, you need to instantiate it like any other object
    - call its constructor (this means you'll need to add a constructor to your
    class).

    Tom Duffy

    "Patel V D" <patel_vikasp@hotmail.com> wrote:
    >
    >Hi All,
    > I have recently started JAVA prgramming.I am confused with the way java
    >handles the creation of object of main class of the program.I mean how and
    >when the object of the main class(Which is the name of the .java file itself)
    >is created.
    > for example,consider the simple program structure
    > class temp
    > {
    > public static void main(String args[])
    > {
    > //some code
    > }
    > }
    > Now,how and when the JAVA creates the object of class temp.
    >
    >Looking forward for reply.
    >Thank you.
    > -Vikas.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center