explain me with a code snippet about the generation and
handling of null point exceptions.

Answer Posted / g.arun

class Test
{
public static void main(String[] args)
{
try
{
int a[] = null;
System.out.println(a.length);
}
catch (NullPointerException n)
{
System.out.println(n);
}

}
}
U can try this by changing NullPointerException in catch
block as catch(Exception e){ System.out.println(n);}

and Using throw it is

class Test
{
public static void main(String[] args)
{
int a[] = null;
System.out.println(a.length);
NullPointerException n = new NullPointerException();
throw n;
}
}

Using Throws

class Test
{
public static void main(String[] args) throws
Exception
{
int a[] = null;
System.out.println(a.length);
}
}

That's all friends hope this one helps you

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is passing by reference in java?

535


What are the three best choices for a development environment?

599


What are the different approaches to implement a function to generate a random number?

565


How will you invoke any external process in java?

602


What does jre stand for?

602






When should I use singleton?

518


What is polymorphism and what are the types of it?

496


Can a constructor call the constructor of parent class?

535


What is the formula to calculate percentage?

530


What is the default access specifier for variables and methods of a class?

566


Can you call a method on a null object?

559


What does system out println () do?

553


Is integer a class?

563


What are the drawbacks of singleton class?

529


What is a static method in java?

535