Menu
Question Index
...

What will be the output of the program?

class ClassDataValidation
{
    public static void main(String arg[])
    {
        Student ashok = new Student("Ashok");

        ashok.print("LINE A");

        ashok.marks = ashok.setMarks(150);
        ashok.section = 'B';
        ashok.print("LINE B");

        ashok.marks = ashok.setMarks(50);
        ashok.section = 'C';
        ashok.print("LINE C");

        ashok.marks = ashok.setMarks(20);
        ashok.section = 'D';
        ashok.print("LINE D");    
    }
}

class Student
{
    String name;
    int marks = 20;
    char section = 'A';

    Student(String name)
    {
        this.name = name;
    }
    
    void setMarks(int marks)
    {
        if( marks >= 0 && marks <= 100)
        {
            this.marks = 35;
        }
    }
    
    void setSection(char section)
    {
        if( section == 'A' || section == 'B' || section == 'C' || section == 'D')
        {
            this.section = section;
        }
    }
    
    void setDetails(int marks, char section)
    {
        setMarks(marks);
        setSection(section);
    }

    void print(String LINEA)
    {
        System.out.println(LINEA + " : " + name + " - " + marks + " - " + section + ".");
    }

}


LINE A : Ashok - 35 - A.
LINE B : Ashok - 101 - B.
LINE C : Ashok - 35 - C.
LINE D : Ashok - 35 - D.
LINE A : Ashok - 20 - A.
LINE B : Ashok - 101 - B.
LINE C : Ashok - 35 - C.
LINE D : Ashok - 35 - D.
LINE A : Ashok - 20 - A.
LINE B : Ashok - 20 - B.
LINE C : Ashok - 35 - C.
LINE D : Ashok - 35 - D.
Compilation Error

Doubts

Problems

Topic: Creating A Class For Data Validation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App