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 |
Which class has no duplicate elements?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
In what type of containers, Border layout is a default layout?
Does sprintf allocate memory?
How can you say java is object oriented?
how can we use the servlet as standalone apllication?should we need to extend any class?
What is java util concurrentmodificationexception?
Is java free for commercial?
What happens if I remove static from main method?
What is polymorphism java example?
What does ide stand for?
Can a class be private?