Topics Index

Abstract Class And Methods >
Siva Nookala - 15 Mar 2016
In Java Array we have discussed about the arrays of primitive data types. We can also create array of objects references and initialize data for each reference (or element) of the array. Objects references are explained in Java Objects References

class Student
    String name;
    int marks;
    char section;
If we have a class Student, we can create an array of the references of the Student as shown below. Here we have a created an array of size 2 and with name students.
Student[] students = new Student[2];
Please note that, when we create an array, only the references are created and not the objects. Hence we need to create the objects separately as shown below at LINE A and LINE B.
students[0] = new Student(); // LINE A
students[1] = new Student(); // LINE B
Once the Student objects are created, then can be accessed using the dot operator (.) as usual.
students[0].name = "David";
students[0].marks = 80;
students[0].section = 'A';

students[1].name = "Pete";
students[1].marks = 72;
students[1].section = 'B';
The program To Print Student Details Using Classes In Java shows an working example of references array.

Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.