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
What is passing by reference in java?
What are the three best choices for a development environment?
What are the different approaches to implement a function to generate a random number?
How will you invoke any external process in java?
What does jre stand for?
When should I use singleton?
What is polymorphism and what are the types of it?
Can a constructor call the constructor of parent class?
What is the formula to calculate percentage?
What is the default access specifier for variables and methods of a class?
Can you call a method on a null object?
What does system out println () do?
Is integer a class?
What are the drawbacks of singleton class?
What is a static method in java?