ExamVeda
Login
Home
This question belongs to Java Program Java Autoboxing
Java Autoboxing
?

What one of the following is best practice to handle Null Pointer exception?
i) int noOfStudents = line.listStudents().count;
ii) int noOfStudents = getCountOfStudents(line);
public int getCountOfStudents(List line)
{
if(line != null)
    {
if(line.listOfStudents() != null)
            {
  return line.listOfStudents().size();
}
}
throw new NullPointerException("List is empty");
}

Answer & Solution
Correct Answer: Option B
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.