• 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

Interface

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 6.
An Interface can never be private or protected.
Answers
True
False
The answer given is False. Can anyone give out an example which an interface is private or protected (including inner interface).
Thanks!
Moon
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only an interface declared in a class can be declared private or protected, thats why the answer is false. The word "NEVER" is used in the question.
HTH
--Farooq
e.g.
===============================================================
class InterfaceTest{
private interface privateinterface{}
protected interface protectedinterface{}
}
===============================================================
[This message has been edited by Muhammad Farooq (edited September 02, 2001).]
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try to compile and run this code:

The output is:
10
I think it is a good example to prove the question.And if you try to compile this code:

The compiler will complain:
Test8.java:1: The type type Foo can't be private. Package members are always accessible wi
thin the current package.
private interface Foo{
^
1 error

------------------
Java lover from hell!
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic