• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

interface!!!

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
in velmurugan notes in interface section it is given that
"if an interface specifies an exception list for a method, then the class implementing the interface need not declear the method with the excpetion list for a method."
this is not clear for me... what i understood by this is following

interface in{public void foo() throws Exception};
class out{ public void foo(){ throw new Exception();}
should not complain as we have defined throws list in our interface..
well this program is not working...
am i missign soemthign
somebody plz help...
thanks in advance
bye
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you must declare class "out" like this:
[CODE]class out implements in[CODE]

Originally posted by sriram gupta:
hi all,
in velmurugan notes in interface section it is given that
"if an interface specifies an exception list for a method, then the class implementing the interface need not declear the method with the excpetion list for a method."
this is not clear for me... what i understood by this is following

interface in{public void foo() throws Exception};
class out{ public void foo(){ throw new Exception();}
should not complain as we have defined throws list in our interface..
well this program is not working...
am i missign soemthign
somebody plz help...
thanks in advance
bye



------------------
Java lover from hell!
 
sriram gupta
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
sorry for the mistake in typing...
my actual program was

interface in{public void foo() throws Exception};
class out implements in{ public void foo(){ throw new Exception();}

but it was not workign... the error i was finding our was related
to not defined error in method foo....
 
sriram gupta
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
sorry for the mistake in typing...
my actual program was

interface in{public void foo() throws Exception};
class out implements in{ public void foo(){ throw new Exception();}

but it was not workign... the error i was finding our was related
to not defined error in method foo....
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all you have placed the ; in the interface wrong.
After that when you trow new Exception I found that this must be in a try catch block or that the overridden foo throws exception
 
sriram gupta
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i think the code given by me is making a lot of confusion..
my actual question was
/*hi all,
in velmurugan notes in interface section it is given that
"if an interface specifies an exception list for a method, then the class implementing the interface need not declear the method with the excpetion list for a method."

*/
so if anybody can tell em what does it means it will be very helpful...
thanks
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI, sriram , let's take a look at some code:

According to the above code, we can reach the following conclusion:
<code>
1. Implementation method in class need not throw the exception defined in the interface, like method1().
2. If the implementation method in class intends to throw any exception, the exception should not be wider than the exception defined in the interface, like method2(). I think that is the reason some interface method throws Throwable since in that case, the implementation method can throw any exception.
3. Implementation method in class cannot throw wider exception that is defined in the interface.
</code>
Hope that helps.
Guoqiao

Originally posted by sriram gupta:


 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice replay Guoqiao!
 
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sriram I think u were missing the try-catch block in ur code. Change ur code from
class out{ public void foo(){ throw new Exception();}
to class out{ public void foo()
{
try{
throw new Exception();
}
catch(Exception e){}

or class out{ public void foo()throws Exception { throw new Exception();}
Correct me if u were not talkign abt it...
------------------
azaman
[This message has been edited by Ashik uzzaman (edited August 19, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic