do you have to declare each object in the array like you did with the class ob1 = new class; or is there an easier way to do it like how you can declare int arrays with a simple for loop?
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
No, it didnt work, ive just tried it and I caught an error. I dont know why, buy it doenst work P.s this is my code if you want to look at: public class Main { public static void main(String[] args) { Food[] refrigerator = new Food[3]; Food food1 = new Food("pizza"); Food food2 = new Food("hamburger"); Food food3 = new Food("hotdog"); refrigerator [0] = food1; refrigerator [1] = food2; refrigerator [2] = food3; for (int i = 0; i
@@Golosovtalks You forgot to input the 'name' in the println statement, it shows the address of the food only if u not include name, hope this can helps for(int i=0; i
bro ur an absolute g. I'm watching and following along with every video in ur java playlist and ur seriously filling in gaps. Im gonna use ur vids for the other languages as well. thanks bro
1:41 I don't understand why he is telling, "give a size if we do not plan assigning values right away". I m wondering arrarys are fixed if we declare size at the initialisation, meaning he have plan to assign 3 values at this program hence he is giving size 3. Is there a way he can increase the size dynamically during the run time if the array size is declared at the initialisation? Pls help to advise if I m missing something.
//******************************************************
public class Main {
public static void main(String[] args) {
//Food[] refrigerator = new Food[3];
Food food1 = new Food("pizza");
Food food2 = new Food("hamburger");
Food food3 = new Food("hotdog");
Food[] refrigerator = {food1,food2,food3};
//refrigerator[0] = food1;
//refrigerator[1] = food2;
//refrigerator[2] = food3;
System.out.println(refrigerator[0].name);
System.out.println(refrigerator[1].name);
System.out.println(refrigerator[2].name);
}
}
//******************************************************
public class Food {
String name;
Food(String name){
this.name = name;
}
}//******************************************************
do you have to declare each object in the array like you did with the class ob1 = new class; or is there an easier way to do it like how you can declare int arrays with a simple for loop?
@@nikleduc1158 You can also do for loops :D
The laziest person who copy this text files :)
@@zhaocheng6114can I use other data types in the array aswell?
Insane this is 3 years old but has done the best job at explaining how to get this done. Bravo!
best videos about programming
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
You can print all three elements using for loop
for(int i = 0; i < 3; i++) {
System.out.println(refrigerator[i].name);
No, it didnt work, ive just tried it and I caught an error. I dont know why, buy it doenst work
P.s this is my code if you want to look at:
public class Main {
public static void main(String[] args) {
Food[] refrigerator = new Food[3];
Food food1 = new Food("pizza");
Food food2 = new Food("hamburger");
Food food3 = new Food("hotdog");
refrigerator [0] = food1;
refrigerator [1] = food2;
refrigerator [2] = food3;
for (int i = 0; i
@@Golosovtalks You forgot to input the 'name' in the println statement, it shows the address of the food only if u not include name, hope this can helps
for(int i=0; i
You can also do that with
for (Food i: refrigerator) {
System.out.println(i.name);
}
You are amazing. Your knowledge and delivering skill is amazing
These videos are very useful for us beginners. Thank you!
bro ur an absolute g. I'm watching and following along with every video in ur java playlist and ur seriously filling in gaps. Im gonna use ur vids for the other languages as well. thanks bro
Short, Simple & Effective. Thanks a ton.
Like a mini skirt
Thank god I can finally organize my fridge.
Youve just given me hope again. Youre such a natural. Thank you very much
Thank you so much, I could understand only watching once. Very good example
great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much
thanks brother we appreciate your efforts ....best of luck
Completely understood, also with for loop for int numbers this time. 31th. Thank you, ma Bro Sensei!
Excelent video, very helpfull to newbies like me!
Well done explained.
Straight to the point nice video♥️
thanks for this great tutorial series
Thank you dude! Now I can write my homework and know more about classes and objects!
Bro is coming in clutch for my cs final tomorrow -- Thank you!
Amazing!!!
nice 1
Wow man, thank you for making this! It really helped
Good video as always
Great
Thank you! This helped me out.
I loved it
Wow!!! im learning❤❤❤ keep it up bro, such a big help for beginners like me.😊
tyanks for your help
Very helpful
nice👌🙌
Great video bro
Thanks🎉🎉🎉😊
if you have to create 30+ objects can you use a for loop to instantiate them?
Sure, something like this might work
Car[] cars = new Car[30];
for(int i = 0; i < 30; i++) {
cars[i] = new Car();
}
Liked it sm
Good video, thanks
Nice
🙏🏻
Good content!
Thanks, bro.
thanx for the help!
Great video
Thanks, Bro!
nice
Thanks a whole lot for this!
This is really great can you do one where the object array can hold objects of different types (non-primitive objects)?
Nice.
Like and comments
❤❤❤
🍱👍
thank bro
Thnak you for all your help
Thank you so much sir.
Thanks, Bro! ☕ You're awesome!
Good goody!
Thank you Bro
noice
thanks bro
Bro code the best
Another banger lesson
i just punched the like button because of One Punch Man.
thank you my Bro ♥♥♥
عربي ؟
best brooo
1:41 I don't understand why he is telling, "give a size if we do not plan assigning values right away". I m wondering arrarys are fixed if we declare size at the initialisation, meaning he have plan to assign 3 values at this program hence he is giving size 3. Is there a way he can increase the size dynamically during the run time if the array size is declared at the initialisation? Pls help to advise if I m missing something.
Using arraylists, you can change the size during runtime
Thanks men
Perfect!
👌👌
Thank you!
Thanks!
Thanks
name is in the Food class object. So how it is associating with main class when you are printing the food name.
Can you explain it please?
lets gooooo
thank you bro
Thanks!!
PEAK
thanks
Cant this be done in the same class?
💙
Can I create an arrayList of objects?
Thank you
Is this array bag?
thank sir
👍
I am a heroooo
how do automatically create an object? what if you allow the user to add a food? how to auto create food4
i like food
Thankssssssss
Very well explained!
thanks for watching Heisenberg!
But how do I enter new value inside the array object
gg
Is pizza your favorite food, cause you mention about it everytime
Being formal, isn’t an array of objects technically called an ArrayList?
Lets get this bread
nais
learnt
Java seems easier than python
Where do you study Bro ?
I feel like I should be paying my college tuition to Bro Code instead.
West Jett
sometimes it seems that you work as an ambassador of pizza companies. But I doesn't matter, as usual thanks