What is the difference between throw and throws ?

What is the difference between throw and throws ?

The throw keyword is used to throwing the exceptionmanually in the program. 

For Example:

 try{throw new NullPointerException();}catch(NullPointerException e){} 

 The throws keyword is used with the method signature with the list of Exceptions type. This process is called exception declaration. It tells the calling method to guard themselves to declare the exception or handle it.

 For example:void calculate(int a,int b) throws ArithematicException{//some calculation code here}


By:Jalees
Date:2012-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher