Menu
Question Index
...

What will be the output of the following program?

class OutPut
{
    public static void main(String arg[])
    {
        Student yogesh = new Student("Yogesh", 67, 'B');
        Student narayan = new Student("Narayan", 72);
        
        Student mahesh = new Student("Mahesh");
        Student kiran = new Student();
                
        System.out.println("Name = " + yogesh.name + ", section = " + yogesh.section + ", marks = " + yogesh.marks);

        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, char sectionParam)
    {
        name = nameParam;
        marks = marksParam;
        section = sectionParam;
    }
    
    Student(String nameParam, int marksParam)
    {
        name = nameParam;
        marks = marksParam;
        section = 'A';
    }
    
    Student(String nameParam)
    {
        name = nameParam;
        marks = 0;
        section = 'A';
    }

    Student()
    {
        name = "Kiran";
    }
}


Name = Yogesh, section = B, marks = 67
Name = Narayan, section = A, marks = 72
Name = Mahesh, section = A, marks = 0
Name = null, section = , marks = 0
Name = Yogesh, section = B, marks = 67
Name = Narayan, section = A, marks = 72
Name = Mahesh, section = A, marks = 0
Name = Kiran, section = , marks =
Name = Yogesh, section = B, marks = 67
Name = Narayan, section = A, marks = 72
Name = Mahesh, section = A, marks = 0
Name = Kiran, section = , 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