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
Explain where variables are created in memory?
Can finally block be used without a catch?
What is difference between public static and void?
Is java written in c?
What is thread synchronization in java?
what is thread? : Java thread
What is package protected in java?
Where import statement is used in a java program?
What is java and their uses?
What was java originally called?
Can we create an object of private class?
What is parsing a sentence?
Is set ordered in java?
Are arrays static in java?
Define iterator and methods in iterator?