Java Hard 1

🧠 Code Challenge


public class Main {
    public static void main(String[] args) {
        Student s1 = new Student("Alice", 92);
        Student s2 = new Student("Bob", 58);

        s1.printResult();
        s2.printResult();
    }
}

class Student {
    String name;
    int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    public boolean hasPassed() {
        return score >= 60;
    }

    public void printResult() {
        if (hasPassed()) {
            System.out.println(name + " passed with a score of " + score);
        } else {
            System.out.println(name + " failed with a score of " + score);
        }
    }
}

  

Explain what this function does. Speak clearly and use keywords.