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("Kiran", 'A');
        
        kiran.print("Kiran", 'A');
        narayan.print("Mahesh", 'B', 65);
        narayan.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;
    }

    Student(String name, char section)
    {
        this(name, 0, section);
    }

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

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


Name = Kiran, section = A
Name = Mahesh, section = B, marks = 65
Name = Narayan, section = A, marks = 72
Name = Kiran, section = A
Name = Mahesh, section = C, marks = 98
Name = Narayan, section = A, marks = 72
Name = Kiran, section = A
Name = Mahesh, section = B, marks = 65
Name = Narayan, marks = 72
Name = Kiran, section = A, marks = 0
Name = Mahesh, section = B, marks = 65
Name = Narayan, section = A, marks = 72
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