• 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
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Private/Protected interfaces

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a question in Abhilash's exam that goes like this:
An Interface can never be private or protected.
True
False
The given answer is FALSE.....
But I wrote this program:
private interface Int
{
void someMethod();
}
public class AQuestion implements Int{
public void someMethod(){
System.out.println("from the implemented method");
}
}
and the compiler complains..... Even if I change the access modifier to protected (for the interface)..... it complains again....
Is the answer in his exam wrong or am I missing something???
Thanks in advance.....
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like a top level interface cannot be private or protected.
I modified your code as below and it works just fine
public class AQuestion {
private interface xint{
void someMethod();
}
class newc implements xint{
public void someMethod(){
System.out.println("from the implemented method");
}
}
public static void main(String args[]){
AQuestion.newc aq = new AQuestion().new newc();
aq.someMethod();
}
}
 
Savithri Devaraj
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where is Abhilash's exam? Anywhere online??
Savithri
 
Shafeeq Sheikh
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There you go:
http://www.angelfire.com/or/abhilash/Main.html
 
Shafeeq Sheikh
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There you go...
http://www.angelfire.com/or/abhilash/Main.html
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interfaces may only be declared public or package access(no access modifier).
reply
    Bookmark Topic Watch Topic
  • New Topic