• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tricky question

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
a tricky question:
(Please do share ur answer/opinions)
Q. Read the code below.
public interface A
{
public abstract void someMethod() throws Exception;
}
Any Class implementing this interface should -
a. necessarily be an abstract class.
b. have the method public abstract void someMethod().
c. have the method public void someMethod() throw an exception which is a subclass of java.lang.Exception.
d. have the method public void someMethod(), which need not throw an Exception.
my answer: C,D but one of my friends suggest B,C,D is it correct???
- prat.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prat
I would go with your friend's answer. The reason B could be correct is if the class we are implementing interface A is declared "abstract" then it will work as we can leave the someMethod() abstract and in that case the B is correct.
Though I didn't know if we could write 'abstract' in a interface method as all methods are abstract by default in the interface
Hope you got it.
Regards
Maulin
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • clearly false
  • well... you could do this if your implementing class is abstract. That's not to say you should do it.
  • once again, you could do this, but I wouldn't say you should
  • this must be the answer the question wants - it includes answer c, and would be the only good candidate for should if it weren't for answer b.
  • Answer d would be the one fairly solid choice if the question had been worded "Any concrete class...". As it is, the question isn't clearly answerable: both b and d are possible, but it doesn't make sense to say that any class should (b) and should (d).
     
    Ranch Hand
    Posts: 1608
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I agree with Steve, a very ambiguous question with no clear answer.
    All you can do is answer it how it has been worded syntactically and hope that the formulator of the question thinks the same way as you do (literally).
    I hate mind reading in exams. You won't find this kind of ambiguity in the exam (at least I didn't anyway).
     
    Ranch Hand
    Posts: 787
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The option b is declaring that this method is abstract. Consequently, the class has to be declared abstract. If class is abstract, any abstract method from implemented interface can be simply ignored if intent is to not to implement them. If this method can be simply ignored, phrase of option is self defeating ".... should have....".
    I find it very causual question...
     
    reply
      Bookmark Topic Watch Topic
    • New Topic