Menu
Question Index
...

What will be the output of the following program?

public class ReferencesAndObjects {
    public static void main(String s[]) {
        Student ref1 = new Student();
        Student ref2;
        ref2 = ref1;
        ref1.name = "Ramu";
        ref2.marks = 90;
        ref1.section = 'A';
        ref2.name = "Kiran";
        System.out.println("Ref1 : " + ref1.name + " " + ref1.marks + " " + ref1.section);
        System.out.println("Ref2 : " + ref2.name + " " + ref2.marks + " " + ref2.section);
    }
}
class Student {
    String name;
    int marks;
    char section;
}


Ref1 : Ramu 0 A
Ref2 : Kiran 90  
Ref1 : Ramu 90 A
Ref2 : Kiran 90 A
Ref1 : Ramu 90 A
Ref2 : Ramu 90 A
Ref1 : Kiran 90 A
Ref2 : Kiran 90 A
Compilation Error or Runtime Error

Doubts

Problems

Topic: Class References And 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