• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interfaces  RSS feed

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the following code valid? If so, please explain how it works
class A{
private interface B{
void callMe();
}
}

class C implements A$B{
public void callMe(){}
}
 
Jasmine kaur
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
this code would definitley give compilation error as u have specified
class class C implements A$B
see you are using keyword implements which means interface and u are using Class A which is wrong and $ sign is wrong and you are yring to call class A and interface together which is wrong.
So please tell me what excatly you want to do this code.
thanks
Jasbir
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code isn't valid. First, the syntax (A$B) is wrong. It should be "A.B" instead.
Second, since the interface "B" has private access, no code outside of class "A" can see it. However if you change the access to "public", "protected" or default (package), it will compile.
The syntax "A.B" simply means the full path to the nested interface "B" within class "A".
Here's a full code example that works.

Note that with a nested (non-static) class, you can't say "new A.D()" since you have to have an instance of "A" before you can create an instance of "D".
Nested classes like this can get nasty, so don't worry if it seems a little confusing at first. Or a lot confusing ;-)
 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Johnson,
Thanks for your explanation.Now iam clear abt the concept of how to access the inner interfaces
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!