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



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

Answer / 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

More Core Java Interview Questions

What is arguments in java?

0 Answers  


what is the difference b/w design pattern and architecture

4 Answers   Covansys,


How do you declare a destructor in java?

0 Answers  


What is a parameter used for?

0 Answers  


You're given a Boolean 2D matrix, can you find the number of islands?

0 Answers   Amazon,


Explain the different forms of polymorphism?

0 Answers  


What is anagram in java?

0 Answers  


byte a=5; byte b=5; byte c=a+b; System.out.println(c); whats the o/p?

7 Answers   NIIT, Wipro,


Why vector is used in java?

0 Answers  


Define packages in java?

0 Answers  


Can a class inherit the constructors of its superclass?

9 Answers   iFlex, Wipro,


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

0 Answers  


Categories