Java Programming Tutorial – 39 – Multiple Constructors

///Java Programming Tutorial – 39 – Multiple Constructors

Java Programming Tutorial – 39 – Multiple Constructors

FavoriteLoadingAdd to favorites

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

source

Java468x60
By |2020-08-18T08:57:27+00:00August 18th, 2020|Java Video Tutorials|48 Comments

48 Comments

  1. A P August 18, 2020 at 8:57 am - Reply

    If anyone is watching this and is confused I recommend this video: https://www.youtube.com/watch?v=T9fRL52TP_M

  2. Harry Holmes August 18, 2020 at 8:57 am - Reply

    Isn't it enough to just create a setTime method assigning the hour, minute, and second variables by itself? Instead of creating set-Hour, -Minute, and -Second methods, I mean.

  3. Hei August 18, 2020 at 8:57 am - Reply

    Guys this is like super?

  4. sumanboi August 18, 2020 at 8:57 am - Reply

    after watching this video 3 times i finally understood something :
    the "this" function or whatever it is jut calls the constructor again with the arguments given in the parenthesis and if the user only enters the hour then by default it will go to the constructor with 3 arguments because of the code: this(h,0,0);

  5. raymond August 18, 2020 at 8:57 am - Reply

    3:24 the errors doesnt dissapear after ive created the constructor
    copied the code straight from the video so does anyone have a clue?

  6. AkimC August 18, 2020 at 8:57 am - Reply

    3:14 Well if I knew that getting rid of my exes was that easy I've started learning java sooner)))

  7. rameen alikhani August 18, 2020 at 8:57 am - Reply

    Java is just beautiful!

  8. Zero August 18, 2020 at 8:57 am - Reply

    actually calling another method in a constructor is not recommended. this is because fields are still being initialised and all fields required by method might not have been set yet.
    so instead of using setTime(h,m,s); in constructor
    just make the 3rd constructor as-

    public tuna(h,m,s){
    this.hour=h;
    this.minute=m;
    this.second=s;
    }

  9. King Og Of bashan August 18, 2020 at 8:57 am - Reply

    Not gonna lie. I used to complete 10 tutorials a day at first. But now it's only 5 tutorials and I got exhausted.

  10. Zachary Golla August 18, 2020 at 8:57 am - Reply

    This is better and has better use of this.

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

    public Tuna () {

    }

    public Tuna (int hour) {
    this.hour = hour;

    }

    public Tuna (int hour, int minute) {
    this.hour = hour;
    this.minute = minute;
    }

    public Tuna (int hour, int minute, int second) {
    this.hour = hour;
    this.minute = minute;
    this.second = second;
    }

    public void setTime(int hour) {
    this.hour = hour;
    }

    public void setTime(int hour, int minute) {
    this.hour = hour;
    this.minute = minute;
    }

    public void setTime(int hour, int minute, int second) {
    this.hour = hour;
    this.minute = minute;
    this.second = second;
    }

  11. Yannick Vankerkhove August 18, 2020 at 8:57 am - Reply

    If you are stuck, remember to search different videos on the topic, like https://www.youtube.com/watch?v=YqBVgUh64Ks in this case. It helps to hear an explanation from different sources.

  12. Cody King August 18, 2020 at 8:57 am - Reply

    Copied this verbatim and it doesn't work… Errors galore.

  13. Luveesh Purswani August 18, 2020 at 8:57 am - Reply

    can you do?:

    public tuna(int…unitsOfMeasurements)

  14. kanika arora August 18, 2020 at 8:57 am - Reply

    Instead of creating so many constructors why can't we use variable length arguments?

  15. Moses Amram August 18, 2020 at 8:57 am - Reply

    You are the best man. i really liked your tutorial . System.out.println("Thank you ")

  16. Harem Abdullah August 18, 2020 at 8:57 am - Reply

    Thanks Bucky!!! This is my second day watching this tutorial and practicing. I am in lesson 39. I think I should take a break and sleep over it because it is getting complicated in my mind.

  17. Jayydol August 18, 2020 at 8:57 am - Reply

    this : points the variable in the current class; this(): it invokes the current class constructor. If this(a), it look for the constructor with one parameter, this(a,b) for two parameters and so on. Calling this(a,b,c) in default or constructors with less parameter is pretty rare.

  18. So I Rape Other Men August 18, 2020 at 8:57 am - Reply

    for those who didn't understand at 4:24 , he meant "where the fuck is that method"
    yeah you're welcome

  19. Ashie Capco August 18, 2020 at 8:57 am - Reply

    What I learned in Computing Class 1 for 2 hours is condensed in 8 mins in this video. Superb work.

  20. 徐宏杰 August 18, 2020 at 8:57 am - Reply

    oh man,after watching Bucky‘s tutorials ,any programming language is a piece of cake

  21. MausomePossum August 18, 2020 at 8:57 am - Reply

    Having a problem, please help!!
    This piece of code I put below is exactly the same as his, but on my screen it has a red error message saying "recursive structure invocation"
    Anybody know what the issue is?

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

    setTime(h,m,s);

    }

  22. spo okey August 18, 2020 at 8:57 am - Reply

    people be complaining, but bucky at least explained it in some way. my teacher at uni just showed us a ready-made program and told us to copy it lol

  23. Zahra Rezai August 18, 2020 at 8:57 am - Reply

    You are like professor Leonard of programming, & thats why I love you and your jokes so much… thank you so much for saving my life…

  24. Петар Ковачовски August 18, 2020 at 8:57 am - Reply

    This keyword basically calls the same class constructor with the matching number of arguments

    Example:
    this(1,2,3);

    calls the tuna constructor with the 3 arguments

    this(1,4,2,3);
    calls the tuna constructor with the 4 arguments(if existing)

  25. Akash August 18, 2020 at 8:57 am - Reply

    Lost me

  26. NUMBOLOKEN SHINDO August 18, 2020 at 8:57 am - Reply

    Why did he use this without a dot seperator in this example instead of using the setTime() function throughout?

  27. CatPerson95 August 18, 2020 at 8:57 am - Reply

    I may be wrong, but i think the "this" on this situation only works because of the overload constructors having the same name "tuna". As he shows, it gave erros until he created the fourth constructor.
    Anyway, I wouldn't use this. Just skip to the next class (getters and setters) and use that instead.

  28. devoiddude August 18, 2020 at 8:57 am - Reply

    Constructors are not methods!

  29. tony Chuks August 18, 2020 at 8:57 am - Reply

    3:16 "and if you watch all my exes just disappeared" that caught me

  30. Fares Ben ayed August 18, 2020 at 8:57 am - Reply

    this way will bring you an overridable method setTime in tuna

  31. Charmle H August 18, 2020 at 8:57 am - Reply

    so, I messed up somewhere and tried to add/make a new project with multiple classes… but all of them say, "package <insert name for package>;" I don't expect a reply (because old video 🙁 but it'd be nice) how do I remove that without breaking my code? or am I hosed?

  32. Hamzza IQ August 18, 2020 at 8:57 am - Reply

    all his exes dissapeared

  33. Modern Warrior August 18, 2020 at 8:57 am - Reply

    OK, if I have a constructor with variable-length argument (e.g: (int…x)),
    and I build more constructors,
    which one will the program choose? Or will it give an error?

  34. TaotheTaoist - August 18, 2020 at 8:57 am - Reply

    every end of video he promises to explain better. I am still waiting…………….

  35. Int Er August 18, 2020 at 8:57 am - Reply

    Bucky went from being one of the better teachers to one of the worst holy shit these vids are getting bad lol

  36. AJay Gupta August 18, 2020 at 8:57 am - Reply

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

  37. Cilicili Bubu. August 18, 2020 at 8:57 am - Reply

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

  38. Chxse August 18, 2020 at 8:57 am - Reply

    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
    }
    }

  39. Walk Alone August 18, 2020 at 8:57 am - Reply

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

  40. mihir pathak August 18, 2020 at 8:57 am - Reply

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

  41. Mendrix REDDIT August 18, 2020 at 8:57 am - Reply

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

  42. Zach Moseder August 18, 2020 at 8:57 am - Reply

    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!

  43. Kumar Academy August 18, 2020 at 8:57 am - Reply

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

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

    }

  44. Ahmad Habib August 18, 2020 at 8:57 am - Reply

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

  45. David Pham August 18, 2020 at 8:57 am - Reply

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

  46. Itayush August 18, 2020 at 8:57 am - Reply

    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!

  47. Randy Diaz August 18, 2020 at 8:57 am - Reply

    Thank you BUCKIE!!

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

Leave A Comment

*