what is difference between throw and throws in exception?
Answer Posted / raju
throw : throw is used to throw exception by user whenever he
feels to throw exceptions. throw is used to throw
either user defined or runtime exception.
for ex : throw new MyException(), here MyException
is user written exception.
throw new NullPointerException(), here
NullPointerException is RuntimeException.
throws: throws is used by the method to throw exception to
the calling method. And method itself does not able
to handle it so it throws to calling method.
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
Is list ordered in java?
What is the difference between math floor and math round?
What is the default access specifier for variables and methods of a class?
How do you do a line break in java?
What do you mean by order of precedence and associativity?
What is the purpose of a transient variable?
Can we override the private methods?
What is equals method in java?
In a container there are 5 components. I want to display all the component names, how will you do that?
Can a static block throw exception?
What is java reflection?
What is the difference between private & public & friendly classes?
List the features of java programming language.
How can you set an applet’s height and width as a percentage?
How is java created?