Examveda

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");
}

A. Option (i)

B. Option (ii)

C. Compilation Error

D. Option (ii) gives incorrect result

Answer: Option B


This Question Belongs to Java Program >> Java Autoboxing

Join The Discussion

Related Questions on Java Autoboxing

What is autoboxing in Java?

A. The automatic conversion of primitive types to their corresponding wrapper classes

B. The process of creating a new box

C. A feature for manually converting wrapper classes to primitive types

D. A feature for boxing objects