Understanding of nested class

Viewed 50

I am trying to understand the below code:

public class StudentManager {
 
    public Student find(String studentID) throws StudentNotFoundException {
        if (studentID.equals("123456")) {
            return new Student();
        } else {
            throw new StudentNotFoundException(
                "Could not find student with ID " + studentID);
        }
    }
}

public Student find(String studentID) throws StudentNotFoundException - is this public Student a nested class? And then we used find(String studentID) a method? Can anyone please help me interpret this code? I am following this link for understanding custom exception handling.

Update:

public class StudentTest {
    public static void main(String[] args) {
        StudentManager manager = new StudentManager();
 
        try {
 
            Student student = manager.find("0000001");
 
        } catch (StudentNotFoundException ex) {
            System.err.print(ex);
        }
    }
}
1 Answers

It is not a nested class. It is a public instance method accepting a studentID parameter as a String that returns a Student and might throw a StudentNotFoundException.

Related