Google Search

Saturday, October 24, 2015

Write a program to explain how array of objects may be created in java.

public static void main(String[] args) {
Student[] studentArray = new Student[7];
studentArray[0] = new Student();
studentArray[0].marks = 99;
System.out.println(studentArray[0].marks); // prints 99
modify(studentArray[0]);
System.out.println(studentArray[0].marks); // prints 100 & not 99
// code
}
public static void modify(Student s) {
s.marks = 100;
}

No comments:

Post a Comment