• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

2 questions

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1.
An Interface can never be private or protected. ? true or false
Q2.
A method can return an Exception ? true or false
Can anybody explain me the answers?
Thanks
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ans1.
true . Too tired to think 'bout it . Too late in the nite(1.45a m) .Will try to think over in the morn' .
Ans2.
Yes a method can return an object of type Exception . And from the docs ---
Class Object is the root of the class hierarchy. Every class has Object as a superclass.
Isn't Exception a Class . Check the docs . U could even get methods that let u manipulate it .
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) True. All methods in an interface must be public. This makes sense since an interface is supposed to represent the public presentation of a class.
2) True. Exception is a class so it is simple enough to create an Exception object and pass it around.


------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. False.
Sorry guys, an 'interface' can be declared 'private' or 'protected' if it is declared inside a 'class'. (see JLS §9.1.1)

Try it, compiles fine; 'course the interface members would still be implicitly public.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane,
DO you mean to say, even if the interface is private,its methods will be public..??
confused
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all methods in an interface are implicitly abstract and public.
According to the Java Tutorial at their site, you may not use the private and protected specifiers when declaring members of an interface.
Hope this helps,
Aakanksha
 
swati bannore
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Aakanksha,
Hey, u r a Ranch Hand, no one yet told u about Naming Policy...(esp Jane?)
[This message has been edited by swati bannore (edited July 17, 2001).]
 
Aakanksha Arora
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeh with this last post I became a ranch hand.
Good observation....i will rectify the same. Thanx
 
please buy my thing and then I'll have more money:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic