Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java

    How to use the Constructor ?
    give the some example


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java

    What did your research tell you? What is confusing about it?
    Suggested reading: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java

    Please write better topic/thread titles. "Java" isn't helpful. "Tell me about constructors" is much better and would alert people that you're asking for basic info that could be easily found in several hundred places on the web and in every Java textbook that's ever been written.

  4. #4
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Java

    a constructor is called when you use the 'new' keyword.

    Is is called when you create a Java object.

    e.g.:

     
    public MyClass()
    {
         // this is the constructor so you would initialise variable etc within this.
         // it is called when you instantiate the object
    }
     
     
     
    MyClass mc1 = new MyClass();                  <----- this will create the object and call the MyClass method (constructor) so anything within the constructor is called at this point.


    You really need to learn Object Orientated Programming and the concept of objects etc.

    To be fair your question was poorly written so dont expect any great responses.