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 lossy conversion in java?
What is an example of declaration?
Explain what access modifiers can be used for methods?
What modifiers are allowed for methods in an interface?
How can you avoid serialization in child class if the base class is implementing the serializable interface?
What are the important features of Java 10 release?
What is difference between static and final?
What is a void method java?
What are the various access specifiers in java?
How do you clear a method in java?
What types of index data structures can you have in java?
What is protected in java?
Is array synchronized in java?
Is an integer an object?
What are JVM.JRE, J2EE, JNI?