Menu
Question Index
...

What will be the output of the following program?

public class ClassDataValidation {
    public static void main(String arg[]) {
        Student ashok = new Student("Ashok");
        ashok.print("LINE A");
        ashok.marks = ashok.setMarks(150);
        ashok.print("LINE B");
        ashok.marks = ashok.setMarks(50);
        ashok.print("LINE C");
    }
}
class Student {
    String name = "Kiran";
    int marks = 20;
    char section = 'A';
    Student(String name) {
        this.name = name;
    }
    int setMarks(int marks) {
        if (marks >= 0 && marks <= 100) {
            this.marks = marks;
        }
        return this.marks;
    }
    void print(String line) {
        System.out.println(line + " : " + name + " - " + marks + " - " + section + ".");
    }
}


LINE A : Ashok - 20 - A.
LINE B : Kiran - 20 - A.
LINE C : Kiran - 50 - A.
LINE A : Ashok - 20 - A.
LINE B : Ashok - 0 - A.
LINE C : Ashok - 50 - A.
LINE A : Ashok - 20 - A.
LINE B : Ashok - 20 - A.
LINE C : Ashok - 50 - A.
Some other output
Compilation Error or Runtime 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