Solved

Complete the Following Code Snippet That Displays a Student's Major

Question 59

Multiple Choice

Complete the following code snippet that displays a student's major, assuming that the method findStudentByID takes a student id as input and returns a result of type Optional<Student>.Also, assume the getMajor method returns a String representing the student's major.
Optional<Student> studentSearch = findStudentByID("123456789") ;
if (____________________)
{
System.out.println(studentSearch.get() .getMajor() ) ;
}
else
{
System.out.println("Student does not exist") ;
}


A) studentSearch != null
B) studentSearch != Optional.empty()
C) studentSearch.isPresent()
D) studentSearch.ifPresent()

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions