#32 Array of Objects in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we are discussing about array of objects:
-- If we create array by default value assign for each type of array
-- The new operator automatically initializes the elements of an array to their default value, which, for example, is zero for all numeric types
and null for all reference types.
-- why we should we know length of array using length property?
-- There is array out of bound exception.

How to create array of object and what does it means?
-- just like to create array for int, float, char we can create array of object
-- when we we create array of object it means we create an array which can hold the reference of object.

e.g
class Student{

}

Student st=new Student();
we know st is reference and new Student() is object.
and st hold reference of student object.

similarly whenever we create array of object
Student sts[]=new Student[5];
it means we can create an array of Student reference type which can hold 5 different reference of
Student object.
sts[0]=new Student();
sts[1]=new Student();
sts[2]=new Student();
sts[3]=new Student();
sts[4]=new Student();

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

you sir have just got another subscriber. beautiful explanation and I wrote so many lines of code until you showed how to simply used those three attributes for ALL of the student objects instead of making one attribute for each object. definitely i am going to check out all of your other videos too. thank you.

sirfmgamer
Автор

First comment from #SriLanka.Thanks you so much for your help

AbdulAhad-ujnf
Автор

The best explanation of Array of Objects in Thank you!🙏

elikmtl
Автор

More precise way

for(Student s: students) {
System.out.println(s.name + ":" + s.mark);
}

HariPrasad-qehd
Автор

I have a list<object[]> which I got from DB query based on few conditions, which contains below location details... I want o/p as segregated locations i.e all cities and zipcodes into its state, all states into country

Cou1 state1 city1 zip1
Cou1 state2 city2 zip2
Cou1 state1 city 3 zip3

O/p sld be as
Cou1
State1
Cit1 - zip1
Cit3 - zip3
State2
Cit2 - zip2

tejaswinigm
Автор

So array is going to store objects values in place of objects ?? Basically in a array each element consists of 3 different student values

jooyeonsimp
Автор

Nice sir, can you do this using with constructor?

pxpjuxk
Автор

Can we use collection framework to create an array of
Thanks in advance

owl
Автор

Getting error when Student class is not Static. But Navin didn't have it as static. What am I doing wrong?

kazialhasan
Автор

Hello Sir,
Getting below error
error: cannot find symbol
Student s1=new Student();
^
symbol: class Student
location: class ArrayObject
ArrayObject.java:4: error: cannot find symbol
Student s1=new Student();
^
symbol: class Student
location: class ArrayObject
2 errors

MY code
class ArrayObject{
public static void main(String a[]){

Student s1=new Student();



}
}

aninditadas
Автор

Is the length property a static attribute of the array object?

actandrepeat
Автор

public static void main(String[] args) use this if showing error

pankajSingh-nhqi
Автор

What is the difference b/w array of objects and collection functionality wise

ankitbaranwal
Автор

public class Main{
public static void main(String[] args) {

Student stud = new Student();
stud.roll = 1;
stud.marks = 88;
stud.name = "Kevin";

Student stud2 = new Student();
stud2.roll = 2;
stud2.marks = 78;
stud2.name = "Marco";

Student stud3 = new Student();
stud3.roll = 3;
stud3.marks = 90;
stud3.name = "Justin";

Student[] students = new Student[3];//Array with references
students[0] = stud;//Manual objects
students[1] = stud2;
students[2] = stud3;

for (Student student : students) {
System.out.print(student.name + " " + student.roll + " " + student.marks + "\n");
}

}
}

class Student {
int roll;
int marks;
String name;
}

kvelez
Автор

How without proper {} this code is working,

You open { in last class and in main method but didn't close it

shaad
Автор

I have two doubts here, 1.When we create an object the class name should be same 2. When we create the three student objects you didnt intialize the data types for rollno, name, marks. If anyone knows please rectify my doubts. Thanks in advance

RaviYash-fsgh
Автор

Why are you not updating VS Code? Please update VS Code.

puruagni
visit shbcf.ru