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 |
What is the purpose of abstract class?
what are literals in java?
What is consumer in java?
Is minecraft 1.15 out?
What are the difference between composition and inheritance in java?
Why are the methods of the Math class are static?
What is the difference between normal report & matrix report?
What is the primary benefit of encapsulation?
Is sizeof a keyword in java programming?
What does it mean that strings are immutable?
What is exception in java?
What does escaping a character mean?