Results 1 to 8 of 8

Thread: role of object

  1. #1
    bhavneetkaur is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default role of object

    class print
    {
    {
    System.out.println("initializer");
    }
    public static void main(String a[])
    {
    System.out.println("main");
    print ob1=new print();
    }
    }

    its output is=main initializer

    but when i dont create object output=main how ?? can anyone explain

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: role of object

    (Moving out of staff only section.)

    Please use [code] tags [/code] when posting code.

    What do you mean by "create object"?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: role of object

    From what I can barely see due to the lack of [code] tags,
    If you have a constructor in a class, and when you make an object, it will call the constructor automatically.
    Please read this: http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

  4. #4
    vikastiwari86 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: role of object

    Quote Originally Posted by bhavneetkaur View Post
    class print
    {
    {
    System.out.println("initializer");
    }
    public static void main(String a[])
    {
    System.out.println("main");
    print ob1=new print();
    }
    }

    its output is=main initializer

    but when i dont create object output=main how ?? can anyone explain



    Hi,
    Java virtual machine always read code from main in java application it means starting point of code is from main method in java application. And as per your code first line of main method is System.out.println("main"); which is go to print main and after the printing main jvm read the second line where you are creating an object of print.
    in your written code you are not created any constructor so jvm provide you default constructor and print object will created and initializer will print....

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: role of object

    bhavneetkaur, you were told about using the code tags in your first thread, a thread you never bothered to return to.

    Do you seriously expect to continue to get free help on a forum without following advice already given or even acknowledging it?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: role of object

    Stop multiposting. I've deleted the two more threads you started with the same question.

    Any more multiposting and you may be banned for a period.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    bhavneetkaur is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Re: role of object

    Quote Originally Posted by DarrylBurke View Post
    bhavneetkaur, you were told about using the code tags in your first thread, a thread you never bothered to return to.

    Do you seriously expect to continue to get free help on a forum without following advice already given or even acknowledging it?

    db
    Java Code:
    i am so sorry sir ,will not happen again

  8. #8
    bhavneetkaur is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Re: role of object

    i am so sorry sir ,will not happen again

Similar Threads

  1. English's role in a job as a programmer
    By Blue Solo in forum Jobs Discussion
    Replies: 1
    Last Post: 11-04-2011, 12:52 PM
  2. Role Division in the development of Web Application
    By jeanjiang in forum Reviews / Advertising
    Replies: 2
    Last Post: 06-20-2011, 02:46 AM
  3. Replies: 0
    Last Post: 12-01-2009, 02:42 PM
  4. Custom role in spring security
    By ngoc61 in forum Web Frameworks
    Replies: 1
    Last Post: 08-07-2009, 03:39 AM
  5. RAndom role dice
    By thenewsaw in forum JCreator
    Replies: 1
    Last Post: 02-07-2009, 02:10 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
  •