//*********************************************** public class Main { public static void main(String[] args) { Car car1 = new Car("Chevrolet","Camaro",2021); //Car car2 = new Car("Ford","Mustang",2022); //car2.copy(car1); Car car2 = new Car(car1); System.out.println(car1); System.out.println(car2); System.out.println(); System.out.println(car1.getMake()); System.out.println(car1.getModel()); System.out.println(car1.getYear()); System.out.println(); System.out.println(car2.getMake()); System.out.println(car2.getModel()); System.out.println(car2.getYear()); } } //*********************************************** public class Car { private String make; private String model; private int year; Car(String make,String model,int year){ this.setMake(make); this.setModel(model); this.setYear(year); } Car(Car x){ this.copy(x); } public String getMake() { return make; } public String getModel() { return model; } public int getYear() { return year; } public void setMake(String make) { this.make = make; } public void setModel(String model) { this.model = model; } public void setYear(int year) { this.year = year; } public void copy(Car x) { this.setMake(x.getMake()); this.setModel(x.getModel()); this.setYear(x.getYear()); } } //***********************************************
@pavelkvasnicka6856 Жыл бұрын
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
@healer352 жыл бұрын
aweeeeeeesome bro..this is the best course in whole youtube
@ibrahimylmaz83782 жыл бұрын
you really got style. you are changing lives Bro. I thank you from the bottom of my heart.
@dianamilenaarchilacordoba46323 ай бұрын
great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much
@soumelee56612 жыл бұрын
wow great explanation
@odaakeenya2 жыл бұрын
you're my dude buddy. nice voice-over, excellent video quality, and easy-to-follow content. God bless you.
@logeshr1761 Жыл бұрын
Superb explanation bro code
@toxicwaste6132Ай бұрын
Really helpful for someone who is learning Java in university thank you my man!
@yahelbraun54714 жыл бұрын
Great explanation! Keep on the good work!
@BroCodez4 жыл бұрын
thanks for watching Yahel!
@mimvt Жыл бұрын
Absolutely easier after you explain everything. Thank you Bro! you save my day
@aram86392 жыл бұрын
excellent explanation, love it
@mahdib93614 жыл бұрын
nice
@nguyenminhquang7052Ай бұрын
Great video!!!!!!
@juanestebanparraparra85312 жыл бұрын
Man, I love your videos, you are so underrated (your videos should have more views)
@nguyennhan3966 Жыл бұрын
you are the best
@kemann38153 жыл бұрын
Awesome
@alexcaesar53774 жыл бұрын
Great Job
@BroCodez4 жыл бұрын
thanks for watching Metin!
@cristianoseixas24172 жыл бұрын
Thanks, excelent
@vincentchoo74714 жыл бұрын
Keep up the great work!
@BroCodez4 жыл бұрын
thank you for watching Vincent!
@theultimateamazing3722 Жыл бұрын
Amazing video! I was looking for copying objects for so long.... thanks bro
@huuloc87193 жыл бұрын
Nice.
@kirillutsenko93062 жыл бұрын
thx for your explanation
@eugenezuev73498 ай бұрын
brilliant
@ShermukhammadKarimov8 ай бұрын
Thanks for the clear explanation.
@Ballnose10 ай бұрын
Brilliant Brilliant explanation and exactly what I needed for my Pokemon game :)
@elionayzuridasilveira41407 ай бұрын
Thank you for this tutorial, Bro!
@bakaiismaiilov47324 жыл бұрын
Love it 👍
@OmerFarukAY-ij2xg7 ай бұрын
I love you bro
@kaushalprasadyadav92422 жыл бұрын
Please make videos for mobile app development....
@pasraju2 жыл бұрын
This is a good explanation!
@unalysuf2 жыл бұрын
Thank you so much for your effort
@hannakhamutouskaya22993 жыл бұрын
You are great!!
@geneolo Жыл бұрын
Thank you Bro🤗How are you doing? This tutorial is great!
@WorstDruidEU2 жыл бұрын
Can someone explain why we used (Car x) as an argument of the copy method? What does this x mean? Is it a placeholder for whatever name we're gonna give to the object? Which object does it refer to?
@mr.prince87012 жыл бұрын
X is the object of type Car that you'll be copying the attributes from. (This)aka car 2 is doing the calling, so u place the attributes from X onto car 2. A copy constructor basically a method that copies the attributes of an object onto another object of the same type. X in this case is Car1.
@_7.T_4 жыл бұрын
thank you my Bro ♥♥♥
@danny.30363 жыл бұрын
Thanks, Bro! ☕ You're awesome!
@danielmilewski76592 жыл бұрын
Thanks bro! Awesome channel!
@ibtesamatif44183 жыл бұрын
what planet are you from .. ? 100% informative
@skillR-2433 жыл бұрын
Thanks bro
@yevgenomelchenko732 Жыл бұрын
Thanks, very helpful!
@曾毓哲-b1t Жыл бұрын
Thank you very much!
@francosalgado45563 жыл бұрын
¡Muchas gracias!
@cdjosh35684 жыл бұрын
Is it good practice to always have a copy method and overload the constructor to copy as well?
@BroCodez4 жыл бұрын
not necessarily but it's a common practice
@tomjohansson35203 жыл бұрын
Thanks, very helpfull!
@MrCoolTester9 ай бұрын
Commenting here just because Bro asked me to do so!
@shubhsharma192 жыл бұрын
commenting for algo, great video
@ramok13032 жыл бұрын
Hello, this video really helped me, but I have a question. Can I accses the values of Car x in the copy method directly like this since the method is in the Car class: public void copy(Car x) { this.setMake(x.make); this.setModel(x.model); this.setYear(x.year); } it worked for me, but i am rather asking. btw I watched almost the entire java playlist (most of it in the 12h. video) and I love the way you're doing it, it's amazing. (sorry for my English)
@mohamedbenkhalifa12992 жыл бұрын
Thanks for pointing this out. It actually works and makes sense. Thanks bro!
@DigitalAstronautOG2 жыл бұрын
You can do that and it will work fine if it is set up in the same way. However, it is best practice to make member variables private and use public/protected getters and setters for them. The reason being is let's say you don't want specific things to be set as the value stored in the variable, you can stop this by handling this in your setter however you would like. Then, the only way you can retrieve that variable is by using the defined getter method (since the member variable has private access). If you're calling the variables from within the class itself, it isn't required that you use a getter and setter (since private access doesn't matter within the same class), but, again, it is best practice to make getters and setters to handle how code is accessed and updated. Hope this helps!
@qpdbwvwdbqp47302 жыл бұрын
Thanks a lot Bro! 🙌 But I had no idea how to do it in non-encapsulated classes :/
@qpdbwvwdbqp47302 жыл бұрын
Oh, finally figured out! //~~MAIN CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class Main { public static void main(String[] args) { Weapon weapon1 = new Weapon("Sword", 10); Weapon weapon2 = new Weapon("Dagger", 5); System.out.println("WEAPON 1:"); System.out.println(weapon1.name); System.out.println(weapon1.damage); System.out.println(); System.out.println("WEAPON 2:"); System.out.println(weapon2.name); System.out.println(weapon2.damage); System.out.println(); //Copying weapon2.copy(weapon1); System.out.println("New WEAPON 2:"); System.out.println(weapon2.name); System.out.println(weapon2.damage); } } //~~WEAPON CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class Weapon { //ATTRIBUTES String name; int damage; //CONSTRUCTORS Weapon(String name, int damage){ this.name = name; this.damage = damage; } //METHODS void copy(Weapon x) { this.name = x.name; this.damage = x.damage; } } [OUTPUT]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WEAPON 1: Sword 10 WEAPON 2: Dagger 5 New WEAPON 2: Sword 10
@romario927303 жыл бұрын
Thanks, Bro!
@mudassirnaz18133 жыл бұрын
Thanks
@stephanieokechi11386 ай бұрын
🎉
@NikoFool2 жыл бұрын
Bro code you are a fucking legend!
@minhtetpaing16953 жыл бұрын
Thank you so much sir.
@annexsoftworks3 жыл бұрын
Thanks bro!
@Simis9992 жыл бұрын
thanks
@suryaa55644 жыл бұрын
Thank You So Much
@bakaiismaiilov47324 жыл бұрын
Bro ? will you be making a video for cloning in java ?
@BroCodez4 жыл бұрын
I'm not sure, it depends if I can fit it into this playlist
@Muhammadfaisal-kd9kx Жыл бұрын
thankyou
@SumbaSlice3 жыл бұрын
amazing, thank you!
@mohammadreza14145 ай бұрын
This is considered a shallow copy right?
@paolobonsignore28133 жыл бұрын
Im kinda confused at this point :/
@yanluisnunezlara3196 ай бұрын
Instances of classes, wether it's either predefined classes in java like String or classes created by programmers, all of them are stored in memory(RAM), this is called data by reference. In the tutorial, copying objects means to do an object point at the same memory space by the reference. Pay attention when the teacher equalize car2=car2 and print both object return the same memory address. I expect that you understand me, I'm not native spiker and have a low level of English.
@gerardonavarro34005 ай бұрын
@@yanluisnunezlara319fué tremenda explicación mi hermano, muchas gracias!
@alexcaesar53774 жыл бұрын
is it possible to change a private method or variables only by getter method in different class? (don't use setter only getter)
@BroCodez4 жыл бұрын
I believe you would need to call some method within the class that contains the private member to access it and change it
@alexcaesar53774 жыл бұрын
@@BroCodez could you give me an example?
@augischadiegils.51094 жыл бұрын
Thanks bro!!
@stefanescu1000 Жыл бұрын
It s pretty easy and logic
@lamias77123 жыл бұрын
Merci Bro
@joshblank45792 жыл бұрын
Bro, how do I make a deep copy of an array?
@TareqRahaman-u6x Жыл бұрын
czx
@ivblock4899 Жыл бұрын
what happen if we don't use this while calling copy method and set method