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 |
Is special character in java?
what do you mean by stream pipelining in java 8? Explain
What is the base class of all classes?
Why heap memory is called heap?
How variables are stored in memory?
how does the run() method in runnable work? : Java thread
What are filterstreams?
Write code to implement bubble sort in java?
Why to use nested classes in java? (Or) what is the purpose of nested class in java?
Explain notify() method of object class ?
What is function and its uses?
Why charat is used in java?