• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Private/Protected interfaces  RSS feed

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
interfaces may only be declared public or package access(no access modifier).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!