Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface within class or interface

 
JigaR Parekh
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • 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 ]
 
rajan singh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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...
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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 public, 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic