Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about catch exception

 
feng lee
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a method throws an ProtocolException(subclass of IOException) which of the following can be used in declaring that method
a. public void method() throws Exception
b. public void method() throw Exception
c. public throws IOException void method()
d. public void method() throws IOException.
e. public void method() throws ProtocolException.
an ,e.Why a is not right?
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by feng lee:
if a method throws an ProtocolException(subclass of IOException) which of the following can be used in declaring that method
a. public void method() throws Exception
b. public void method() throw Exception
c. public throws IOException void method()
d. public void method() throws IOException.
e. public void method() throws ProtocolException.
an ,e.Why a is not right?

u bet. a,d and e are correct.
 
Steve Leung
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
It seems depend on the method we implement is override the a method or superclass of that class. If we implement subclass of that class, only e is valid.
 
Shanmugam Karthikeyan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello please explain it clearly...

i cound't understand your answer
if possible , state some example which justifies your arguments
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic