Menu
Question Index
...

What will be the output of the following program?

class ReferencesAndObjects
{
    public static void main(String s[])
    {
        Student st1 = new Student();
        Student st2 = new Student();
        st1 = st2;

        st1.name = "Rajesh";
        st2.marks = 87;
        st1.section = 'C';
        
        System.out.println("Print using st1 : " + st1.name + " " + st1.marks + " " + st1.section);

        System.out.println("Print using st2 : " + st2.name + " " + st2.marks + " " + st2.section);

    }
}

class Student
{
    String name;
    int marks;
    char section;
}


Print using st1 : Rajesh 0 C
Print using st2 : null 87
Print using st1 : Rajesh 87 C
Print using st2 : Rajesh 87 C
Print using st1 : null 0
Print using st2 : Rajesh 87 C
Compilation Error
Runtime Error

Doubts

Problems

Topic: Member Variable 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