aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Interface doubt" Watch "Interface doubt" New topic
Author

Interface doubt

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

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

Source of the question


Every member type declaration appearing within the body of a directly enclosing interface is implicitly static and public.


Please give me example of this statement.


Thanks and Regards,
cmbhatt


cmbhatt
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Chandra Bhatt:
quote: Every member type declaration appearing within the body of a directly enclosing interface is implicitly static and public.

Please give me example of this statement...

Writing your own example would be great practice.

Define an interface with a member type (class or interface) that is not explicitly static or public. Then write code that demonstrates this member type is static (does not require an instance of the enclosing type) and public (can be accessed from another package).


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by swarna dasa:

Uh... That's rather explicit. I think we're looking for a demonstration that "public" and "static" are implicit here.
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
Yup.. it is explicit, thought he was questioning the answer (a,f) abstract and public. So had an example with the possible modifiers.

Here is the one (hopefully) exhaustive example

com InterfaceTest.java


test ClassTest.java //name it whatever you want it



Output

>java test.ClassTest
1
2

>java test.ClassNestedClassTest
3
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
Here are a couple of examples.

Consider this code.



Notice that the main method is in a static context, and, therefore, you cannot access non-static members of the class from it.

Notice that you can create an instance of Test, the member class inherited from Test1, without any problem.

However, the inner class Test3 from the class Test2 cannot be accessed from the main method without an instance of Test2.

This shows that the class Test defined in the interface Test1 is implicitly static.

To show that the members are implictly public, you can look at the message the compiler gives you if you try to use another access keyword on the member.



If you try to compile this, you get the following error message.

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Thanks marc, swarna and Keith for your prompt reply.

I got my answer!


Thanks and Regards,
cmbhatt
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Interface doubt
 
Similar Threads
Nested Interface Declarations within Interfaces
Interfaces in java
interface within class or interface
interface and extends
Interfaces in java