aspose file tools*
The moose likes Mock Exam Errata and the fly likes abhilash Q6, Q59, Q60: about interface & class defined inside an interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "abhilash Q6, Q59, Q60: about interface & class defined inside an interface" Watch "abhilash Q6, Q59, Q60: about interface & class defined inside an interface" New topic
Author

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

yi miao
Greenhorn

Joined: Jun 29, 2001
Posts: 6
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.

Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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

Joined: Jan 09, 2001
Posts: 1492
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.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abhilash Q6, Q59, Q60: about interface & class defined inside an interface
 
Similar Threads
Question on Interface
doubt : class defined inside an interface
Doubt on Class defined inside an interface
interface
Question on Interface