Menu
Question Index
...

What will be the output of the following program?

public class College {
    public static void main(String[] args) {
        Student[] student = new Student[2];
        student[0] = new Student();
        student[0].name = "Khan";
        student[0] = new Student();
        student[0].name = "Kittu";
        student[1] = new Student();
        student[1].name = "Munna";
        for (Student element : student) {
            System.out.print(element.name + " ~ ");
        }
    }
}
class Student {
    String name;
}


Khan ~ Munna ~
Kittu ~ Kittu ~
Kittu ~ Munna ~
Compilation Error or Runtime Error

Doubts

Problems

Topic: Creating Array Of Objects In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App