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 benefit of inner / nested classes ?
Mention a package that is used for linked list class in java.
What is meant by class loader? How many types are there?
Is it possible for a yielded thread to get chance for its execution again?
What is the default size of arraylist in java?
There are two classes named classa and classb. Both classes are in the same package. Can a private member of classa can be accessed by an object of classb?
What is initial size of arraylist in java?
Explain different ways of creating a thread. Which one would you prefer and why?
Can we nested try statements in java?
Lowest Common ancestor in a Binary Search Tree and Binary Tree.
How objects are stored in java?
what is aggregation in java?
What is the difference between static and non-static variables in java programming?
Give me example of derived data types.
Why set do not allow duplicates in java?