Array of Objects in Java Tutorial

Sharing buttons:

so in this video we'll talk about array

of objects now what I mean by objects

are so let's say we have a class called

as student and this class I have some

let's I have two variables one is

private why to go grab it will directly

go with our table with scope we'll go

for a string s name and we'll have

string on our string maybe and roll

number so let's say have we have this

two details what is s name and second is

roll number and to assign the value to a

constructor will use okay we'll go for

insert code we'll go for the constructor

which will take two parameters and then

we'll also go for a method which is

tostring just to put in the value so I

hope you are familiar with the method

which is two strength so we'll go for

insert code and two string for both the

variables so if you're not familiar with

what is two string method just go to my

channel you will find a method or you

will find a video on tostring so here

what we have is let's say we have the

first student as s1 and the values for s

1 let's say student so we can have

student let's say the first value as

nubbin and it all number is 1 not 1 then

we have one more student just with can

just copy this code you know and this is

student 2 and name will be let's say

more hit and this is 2 let's have one


we'll say 3 and this term will have

let's say OSHA and this is 3 so now we

have these three names with num with low

numbers what happens if I find the value

so it's a as out and let's print the

value of s1 now as soon as I try to

print the value of s1 as right click and


so you can see it's printing a student

name and roll number what happens if I

pray into s2 so if I print or s1 easier


say copy and paste paste this is a stew

and s3 and if I print all the values it

will pray in now in Mohit anusha and all

those values clear but Walter you was a

use of addy so using an ax we can have

one object which is an add he will have

all this elements so how to get an added

we can simply say student this time we

are not going for a one value we are

going for adding of value so we have to

give a bracket I will say this is

students and will say new student now

what is this this is just a connection

of three values okay now how to set the

values that we have to say student of

zero a yeah so do we have three objects

now the problem is we don't have three

objects we just have three we have three

reference so this student is not a

collection of objects this is collection

or area of reference so even if your

topic is adding of objects we never have

area of object we always have area of

reference so here what we do is we can

assign student students as 0 will be as

1 then we can have a copy paste paste so

this is 1 this is 1 and this is 2 this

will be 2 & 3 so this is how we create a

dia of students so basically this is not

this is not adding of objects this is a

D of reference and these are your

objects s1 or these are your objects new

Neil Neil cool so even if you have to

strain to type a date don't have chance

object with AB student reference added

ok now how to print this values so we

can use a for loop we can use and ask

for loop here so we can say student as :

students students and then we can print

the value of s so this is also possible

when you run this so you can see we got

all the ops

so we are not getting we are distributed

to remove this part so when you say

you're getting this output it's all

because of this valuables here okay so

this is your add-in saw to plate a day

of reference so we have to create a

class named they can they add a name and

then we have to say a new student so

mind you once again this is not a day

off object this is a day of reference

just to make your point clear clear

that's from this video we talked about

area of reference so thanks for watching