Menu
Question Index
...

What will be the output of the following program?

class OutPut
{
    public static void main(String arg[])
    {
        Student narayan = new Student("Narayan", 72);
        Student mahesh = new Student("Mahesh");
        Student kiran = new Student(" ");

        System.out.println("Name = " + narayan.name + ", section = " + narayan.section + ", marks = " + narayan.marks);

        System.out.println("Name = " + mahesh.name + ", section = " + mahesh.section + ", marks = " + mahesh.marks);

        System.out.println("Name = " + kiran.name + ", section = " + kiran.section + ", marks = " + kiran.marks);

    }
}

class Student
{
    String name;
    int marks;
    char section;
    
    Student(String nameParam, int marksParam)
    {
        name = nameParam;
        marks = marksParam;
        section = 'A';
    }
    
    Student(String nameParam)
    {
        name = nameParam;
        marks = 0;
        section = 'A';
    }
}


Name = Narayan, section = A, marks = 72
Name = Mahesh, section = A, marks = 0
Name = null, section = A, marks = 0
Name = Narayan, section = A, marks = 72
Name = Mahesh, section = A, marks = 0
Name = , section = A, marks = 0
Name = Narayan, section = A, marks = 72
Name = Mahesh, section = A, marks = 0
Name = Mahesh, section = A marks = 0
Compilation Error
Runtime Error

Doubts

Problems

Topic: Class With Multiple Constructors 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