• 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

Interfaces in java

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
i am new to java ranch.
Please explain me the below questions with examples.

1.Which of the following are modifiers that can be applied to an interface that is a member of a directly enclosing interface?

a. abstract
b. implements
c. final
d. private
e. protected
f. public

Answer: a,f

2.Which of the following are modifiers that can be applied to an interface that is a member of a directly enclosing class?

a. abstract
b. extends
c. final
d. private
e. protected
f. public

Answer: a,d,e,f

Regards,
Seema
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in intefaces only public and default level(package level) modifiers are allowed . In in class all 4 level access modifers are allowed.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In an interface the default access modifier is 'public'. So if you don't specify an access modifier for a method in an interface, the method is automatically 'public' (and not only package visible, as in a class).

See section 6.6.1 of the Java Language Specification:

"All members of interfaces are implicitly public."
 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My doubt is:
1.Does an interface with another interface is possible?
2.Does an interface within a class is possible?
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Seema Sharma:
My doubt is:
1.Does an interface with another interface is possible?
2.Does an interface within a class is possible?


You should write a small program to find it out.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See, Try to understand from OOPS perspective.
why we should define like that??
An interface with in an interface and in a class?
what are the advantages we will get??
try to write small programmes regarding this?
I cam teel you the Answere here but you should learn by yourself. that is the motto in this forum.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Seema Sharma
for your both questions anwser is YES.
if we come to modifiers:
if the enclosing one is interface, we can have only public or abstract(like any other interface method). If we inter into inner interface all rules of normal interface will apply.
if the enclosing one is class, we can have all four(private, protected,public and default) modifiers. If we inter into inner interface all rules of normal interface will apply.
like this we can have class in interface also.

Regards
Mallik Avula
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Krishna
could you please explain what is that purpose of defining an interface within an interface or a class??

when a class implements an interface that has an innerInterface....is that not necessary to implement the methods inside the inner interface

Thanks
Sudarsan
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the below code.
If you define a interface inside Interface or a class, its nothing but they are the memebers of those interface or class.

 
Seema Sharma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic