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 |
What is arguments in java?
what is the difference b/w design pattern and architecture
How do you declare a destructor in java?
What is a parameter used for?
You're given a Boolean 2D matrix, can you find the number of islands?
Explain the different forms of polymorphism?
What is anagram in java?
byte a=5; byte b=5; byte c=a+b; System.out.println(c); whats the o/p?
Why vector is used in java?
Define packages in java?
Can a class inherit the constructors of its superclass?
Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?