Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


explain me with a code snippet about the generation and
handling of null point exceptions.



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

Post New Answer

More Core Java Interview Questions

Is special character in java?

0 Answers  


what do you mean by stream pipelining in java 8? Explain

0 Answers  


What is the base class of all classes?

0 Answers  


Why heap memory is called heap?

0 Answers  


How variables are stored in memory?

0 Answers  


how does the run() method in runnable work? : Java thread

0 Answers  


What are filterstreams?

0 Answers  


Write code to implement bubble sort in java?

0 Answers  


Why to use nested classes in java? (Or) what is the purpose of nested class in java?

0 Answers  


Explain notify() method of object class ?

0 Answers  


What is function and its uses?

0 Answers  


Why charat is used in java?

0 Answers  


Categories