• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

interface within class or interface

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found following two question which are confusing me.

1) 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: ADEF

2) 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: AF



Thx
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, at least one of the stated answers is incorrect. Where did you find these questions and answers? I advise you to simply ignore the given answers. What do you think the answers should be, and why?
[ July 17, 2005: Message edited by: Jim Yingst ]
 
JigaR Parekh
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are right.
Second quetion i feel is correct and answer is also right.
bcoz default behaviour of an interface is abstract and it should be always public
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim Yingst,
please spot an error. Both answers looks correct for me.

This code is compiled just fine:

[ July 18, 2005: Message edited by: George Bolyuba ]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
according to me answeres are correct...

1.
since interface is member of class Test. It means we can apply any modifiers which we can apply to member of class. That is why we can provide public ,private and protected modifiers.
abstract is redundant but we can apply it.

2.
in interface we can never have private or protected modifiers.
so modifiers for member of interfaces are
public
final static
abstarct(redundant)
and we can never use final with interface because intefaces are meant to be implemented.

please let me know if i am wrong...
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

default behaviour of an interface is abstract and it should be always public


The public modifier is optional. An interface without an access modifier has package level access.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[rajan]: and we can never use final with interface because intefaces are meant to be implemented.

But what about this:
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[jigar]: default behaviour of an interface is abstract and it should be always public

[Roger]: The public modifier is optional. An interface without an access modifier has package level access.


Ah, we seem to have lost some context here. Jigar was referring to the second question, which has an interface nested within another interface. This nested interface in implicitly coderanch, not package - not because it's an interface, but because it's nesteed within another interface. All members of an interface are implicitly public; this includes nested classes and interfaces.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic