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, 'A');
        Student mahesh = new Student("Mahesh", 98, 'C');
        Student kiran = new Student(null, 0, '0');
        
        kiran.print();
        narayan.print();
        mahesh.print();
    }
}

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

    Student(String name, int marks, char section)
    {
        this.name = name;
        this.marks = marks;
        this.section = section;
    }

    void print()
    {
        System.out.println("Name = " + name + ", section = " + section + ", marks = " + marks);
    }
}


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

Doubts

Problems

Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App