What is the catch or declare rule for method declarations?



What is the catch or declare rule for method declarations?..

Answer / amit2009mca

the catch and decalre rule to handle the exception
1)when we don't want to handle the particular exception
we declare it
means to say that imagine that you go to market class
and call the purchase method to purchase a book.
but the shopkeeper has n't the particular book so its
responsibility to shopkeeper that he inform you about
particular exception so he declare the exception
Booknotfound and throws like this
class Market
{
public void purchase throws booknotfound
{
}
}
so this is called the declare rule

another is
2)catch
imagine you call the purchase method to buy book but there
is some problem like book is tore up or book is in godown
so its peoblenm pf the sopkeeper so its responsibility of
shopkeeper to handle this particular exception
then the Catch rule comes in a ligtht
like theis
class Narket
{
public purchase()
{
try{
}
catch(Booktoreupexception e or BookinstoreException e)
{
}
thanks if you got this because these all are just for
checked exception thanks
AMIT SINGH09(amitsing2008@gmail.com) thanks

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

How many types of design patterns are there?

0 Answers  


How do you start a thread?

0 Answers  


What is void class in java?

0 Answers  


What is double in java?

0 Answers  


What is the purpose of extern variable?

0 Answers  






why java does not support unsigned keyword?

1 Answers  


What is a singleton factory?

0 Answers  


What types of index data structures can you have in java?

0 Answers   Tech Mahindra,


What is variable explain with example?

0 Answers  


class A { public void disp(int a,int b) { System.out.println("hai"); } } class B { public void disp(int a,int b,int c) { System.out.println("hai"); } } above program is overloading or overriding?

9 Answers   Infosys, Wipro,


What is the collections api?

0 Answers  


What will be the initial value of an object reference which is defined as an instance variable?

0 Answers  


Categories