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 a cup of java?
What is the hashcode () and equals () used for?
Where pragma is used?
What isan abstract class and when do you use it?
How can you write a loop indefinitely in java programming?
Does java isempty check for null?
Can we declare register variable as global?
when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service
Name container classes in java programming?
Describe different states of a thread.
What is anagram number?
How do you use, call, and access a non-static method in Java?