There are many points between Throw and Throws in Java . Some of them are given below:-
Sr No. | Throw | Throws |
1 | It is used to throw exceptoin explicity. | It is used to declare exception. |
2 | throw keyword is used. | throws keyword is used |
3 | Multiple Exception can't be thrown. | Multiple Eception can be thrown. |
4 | It is used within the method. | It is used with method signature. |
5 | Construcor cannot be inherited by subclass. | Method can be inherited by subclass. |
6 | Constructor is call when object is created. | To call method, new operator is used. |
Java Throw Example:-
void display()
{
throw new ArithmeticException("welcome");
}
Java Throws Example:-
void m()throws ArithmeticException
{
//method code
}
3 Comments
Useful
ReplyDeleteYes , very useful.... ty bhai for this.....
ReplyDeleteTy to all
ReplyDelete