Java Programming Tutorial – 39 – Multiple Constructors

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






30 responses to “Java Programming Tutorial – 39 – Multiple Constructors”

  1. AJay Gupta Avatar

    whats the point of using this(0,0,0), this(h,0,0)…in every constructor function???

  2. Cilicili Bubu. Avatar

    I still dont understand why need put sethour setmin setsec
    Why cannot directly
    second=s; like the tutorial be4

  3. Chxse Avatar

    Easiest way of demonstrating how each of the constructors will work based on how many parameters you use. Remember we can assign values for constructor parameters by doing myclass class obj = new myclass(parameter).

    class myclass {
    private int a;
    private int b;

    public myclass() {
    System.out.println("This is the first constructor, no args");

    public myclass(int a) {
    System.out.println("This is the second constructor, one arg " + a);

    public myclass(int a, int b) {
    System.out.println("This is the third constructor, two args " + a + b);

    public static void main(String args[]) {
    myclass classobj = new myclass(); // uses the first constructor
    myclass classobj2 = new myclass(1); // uses the second constructor
    myclass classobj3 = new myclass(1,2); // uses the third constructor

  4. Kashish Shakil Avatar

    awesome tutorials..u cn learn new concept each time in short duration

  5. mihir pathak Avatar

    can't this be done using "variable length arguments" instead of creating so many constructors

  6. MendrixMC Avatar

    So bucky is fluent in every possible programming language there is, but does not know how to use ctrl+c.

  7. Zach Moseder Avatar

    What if you wanted one of the parameters to be random? How would you do this using a new constructor to call an already made one by the this() statement?

    I've tried writing out a random number generator but ran into an error that said the "this" statement must be the first line.

    Thanks! And if you don't get around to this question, thanks anyway for your vids!

  8. 600 Seconds Avatar

    why the fuck is this giving error
    public class t39 {
    private int hour;
    private int minite;
    private int second;

    public t39(){
    public t39(int h){
    public t39(int h,int m){
    public t39(int h,int m,int s){


  9. pratik patil Avatar

    what is difference between hour and this.hour?

  10. Kaiser Khan Avatar

    arguments are the values passed to a method

  11. Bhanesh Bhadrecha Avatar

    This examples are more clear and tidy. Thx

  12. Ahmad Habib Avatar

    I didn't get that .. why he didn't used this(h , m , s);
    in 4th constructor too..??

  13. paulaxa1 Avatar


  14. zieben64 Avatar

    Bucky, I can't tell you enough how grateful I am of your videos. I've overcome numerous hurdles with the huge help from your videos. The one helped me create multiple JPanel popups all in 1 class. sweeeeet.

  15. TheMadFloppy Avatar

    damn this was pretty complicated

  16. David Pham Avatar

    LOL dis guy said: "but the meat of this video is here…"

  17. Patrick Balech Avatar

    wasn't it easier to assign hour,minute and second in the third constructor directly?

  18. Itayush Avatar

    So far I've understood everything in your tutorial series of Java perfectly (I believe), until now.
    I just don't get the how it works. Why having so many constructors and what are their purpose?
    Thanks in advance for any answers!

  19. Randy Diaz Avatar

    Thank you BUCKIE!!

    Your the best bro i watched the c++ videos and now im learning java!

  20. Eugene Kuzmov Avatar

    can you guys explain the difference btw a method and a constructor?

  21. Devin M Avatar

    if bucky really wanted to be lazy, he should use shortcut keys like ctrl+c, ctrl+v, ctrl+shift to highlight, and all other sorts of stuff

  22. waa2a0 Avatar

    when I type this code it keeps telling me that my methods have to specify a return type. why doesn't bucky have to give those constructor methods a return type?

  23. TheUltimateProgrammer Avatar

    I though this is used to use instance variables instead of local variables if the variables have the same name

  24. Subhadarshi Samal Avatar

    use of this keyword is not understood. which constructor is called by this()??

  25. Mervin Lee Avatar

    I am not sure sure if this question is a meaningful one but when you typed: public tuna (int h) {} for the one argument, how would this constructor know that the int h means our because in the class method, you only typed int hour and not int h? I hope that you understand what I am trying to ask here but any assistance would be appreciated.

    My other question is why do you only have the setTime for all three constructor and this() for the first two arguments? I am a bit confused between setTime and this(). Thanks!

  26. Joshua Caponong Avatar

    Hey is there a get and set accessor in java? just like in c#? for public property

  27. Meshal Alawwad Avatar

    Can you use methods instead of multiple constructors?

  28. Mako Young Avatar

    For anyone having trouble with their "this" in this part of their code (Tiger means Tuna lol sorry I changed it)

    public class tiger{
    private int hour;
    private int minute;
    private int second;

    public tiger(){
    public tiger(int h){
    public tiger(int h,int m){
    public tiger(int h, int m, int s){

    Just change "this" into "setTime"

    public class tiger{
    private int hour;
    private int minute;
    private int second;

    public tiger(){
    public tiger(int h){
    public tiger(int h,int m){
    public tiger(int h, int m, int s){

    have no Idea why it works but because these tutorials are old this was the only way I found of fixing the code without it error'ing.

  29. utkarsh716 Avatar

    what the hell is 'this'.. 😐

  30. A Shell Of My Former Glorious Self Avatar

    actually you only need 2 constructors for this: default and the constructor with 3 parameters:

    //default constructor
    public tuna()
    this(0,0,0); //or call setTime(0,0,0) directly to reduce the number of calls which is performance overhead

    //constructor with 3 parameters
    public tuna(int h, int m, int s)

    the others just make the code confusing for beginners.

    then inside main():

    tuna tunaObject01 = new tuna(4,0,0); //if you want to only set the hour (set the others to 0)
    tuna tunaObject02 = new tuna(4,2,0); //if you want to only set the hour and minute (set the others to 0)

Leave a Reply

Your email address will not be published. Required fields are marked *