• 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

abhilash Q6, Q59, Q60: about interface & class defined inside an interface

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 6.
An Interface can never be private or protected.
Answers True or False ?
The answer is False. I don't understand in what situation the interface could be private or protected?
Question 59.
Interface methods can be declared with the following modifiers
1 public
2 none (i.e., no access modifier).
3 private.
4 static
5 native
6 synchronized.
The answer is 1 and 2. But according to <<Exploring JAVA>> by Patrick Niemeyer & Joshua Peck, it says:"The methods of an interface are always considered public"(p167). So could 'none' be a modifier of interface?
Question 60.
Which of the following are true about the class defined inside an interface
1 it is not possible in the java Laungage.
2 The class is always public.
3 The class is always static.
4 the class methods cannot call the methods declared in the interface.
Answer is 2, 3&4. Could sb. give me an example how to create the instance class? Should we implement the interface first?

5 the class methods can call only the static methods declared in the interface.

 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,
I could think of 1 zillion reasons why my interfaces should be private or protected. I really don't like sharing with strangers!
The question doesn't require you to explain when an interface can be private or protected, just so that you know the JVM doesn't restrict access modifiers on interfaces.
Interface methods are always considered public. Think of it this way: If I don't place an accessor on an interface method the compiler will place "public" there. The same as default constructors. The trick here is that none doesn't specify default as in class methods.
Regards,
Manfred.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,
An example of class being define inside interface. From the answers you can deduce that the class will be static and public. What does that mean? It means that you don't need an interface object to create the class! See code following.

Regards,
Manfred.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yi,
Just to add to Manfred's response. You can define an interface as a member of a class; in which case it may be private or protected.

The above won't cause an error. The question is just trying to emphasize that not all interfaces are public.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
reply
    Bookmark Topic Watch Topic
  • New Topic