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 3 of 3

Thread: get a help about multiple constructors

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default get a help about multiple constructors

    what's the different between constructors in bold
    what's the use of this keyword

    public class apples {
    private int hour;
    private int min;
    private int sec;
    public apples(){
    this(0,0,0);
    }

    public apples(int h){
    this(h,0,0);

    }
    public apples(int h,int m){
    this(h,m,0);
    }

    public apples(int h,int m,int s){
    set(h,m,s);
    }
    public void set(int h,int m,int s){
    hour= ((h>=0 && h<24)? h:0);
    min= ((m>=0 && m<60)? m:0);
    sec= ((s>=0 && s<60)? s:0);
    }
    Last edited by helloworld922; December 1st, 2012 at 02:42 PM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: get a help about multiple constructors

    different between constructors in bold
    Different args list.
    this is a reference to the current class object when executing code in a class.

    See the tutorial: http://docs.oracle.com/javase/tutori...O/thiskey.html
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Heshan Sandamal (November 30th, 2012)

  4. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    My Mood
    Cold
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: get a help about multiple constructors

    Hello

    1. This class constructor has been overloaded to take different parameters .
    2. The methods are called the minute this classes own constructor is called
    3. The created set method takes 3 parameters and the output will be different depending on the parameters passed to it, by definition of the code inside the actual set method.

    I hope this helps.

  5. The Following User Says Thank You to steven_bishop For This Useful Post:

    Heshan Sandamal (December 1st, 2012)

Similar Threads

  1. Replies: 1
    Last Post: April 26th, 2012, 10:06 AM
  2. Replies: 6
    Last Post: December 9th, 2011, 04:53 PM
  3. Constructors
    By av8 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 19th, 2011, 06:40 PM
  4. constructors in servlets
    By the light in forum Java Servlet
    Replies: 3
    Last Post: June 27th, 2011, 04:13 AM
  5. [SOLVED] Overloading constructors(Multiple Constructors)
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 11th, 2011, 12:55 PM