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 |
Why main method is called first in java?
Which method is used to find that the object is exited or not?
Is minecraft 1.15 out?
Is arraylist ordered?
What is appletviewer?
Explain the difference between throw and throws in java?
How to find the size of an array a)array.length() b)array.length c)array.size() d)array.size
If all the methods in abstract class are declared as abstract then what is difference between abstract class and in interface?
Do you need to import math in java?
Is c better than java?
What is java util collection?
Why string is not thread safe?