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 common usage of serialization?
what type of questions asked for barclays technologies pune please send urgent
What an i/o filter in java programming?
How does compareto work in java?
Is java still relevant?
What is the r character?
What are the difference between string, string builder, and string buffer in java?
What is currentthread()?
What are identifiers in java?
Name and explain the types of ways which are used to pass arguments in any function in java.
Can we create more than one object singleton class?
What is complexity and its types?
What is hasnext in java?
How to reverse string in java?
What are the differences between wait() and sleep()?