explain me with a code snippet about the generation and
handling of null point exceptions.
Answer Posted / 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 View All Answers
What is the basic concept of java?
What is ellipsis in java?
Is jdk required on each machine to run a java program?
What is a method header?
What is javac used for?
Do I need java on my computer?
What is function and method in java?
Can list contain null in java?
How are java objects passed to a method and what are native methods?
What is the collections api?
In how many ways we can create threads in java?
What is fail fast in java?
Why do we need singleton class?
What is the difference between a loader and a compiler?
What is the new line character?