permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface within class or interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interface within class or interface" Watch "interface within class or interface" New topic
Author

interface within class or interface

JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
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

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
JigaR Parekh
Ranch Hand

Joined: May 23, 2005
Posts: 112
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

Joined: Feb 18, 2005
Posts: 162
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 ]

SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
rajan singh
Greenhorn

Joined: Jun 08, 2005
Posts: 17
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

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[rajan]: and we can never use final with interface because intefaces are meant to be implemented.

But what about this:
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface within class or interface