• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Interface Question - Can you answer it?

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I came across the following question that I am unable to answer
14)
Which of the following statements is true?

a) An interface can contain a nested top-level inner class.

b) An interface can contain a member inner class.

c) A member inner class can implement an interface.

d) A static method can contain a local class.

e) A static method can contain a nested top-level class.


I think the answer is b and c. Could anyone else confirm this for me?

Thank you
David
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe d is also correct.



a and e can't be true because according to the Java Language Specification, nested class and top-level class have opposite meanings.
 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply. I think you are right about D as well.
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Could you please clarify some terms related to inner classes ?

[*]Regular Inner Classes
[*]Inner Classes
[*]Nested Classes
[*]Top Level Classes
[*]Top Level Nested Classes
[*]Top Level Inner Classes

I think some terms refer to the same concept but I am confusing.

K&B book refers to Top Level Nested Classes as static but I according to previous post from Keith, nested and Top Level have opposite meanings.

I'm very confusing about the terms.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at Q30 on free download from inner classes. Hope it helps.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think a,c,d is correct
for b) there are some misunderstanding .
In the interface ,fields(include class and interface ) are public and static despite we don't add these modifers to them, if so the complier will do that thing
Also methods are public and abstract
[ March 02, 2006: Message edited by: Changchun Wang ]
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for me, question a) does not make sense. either the class is nested or it is a top-level class. Changchun, would it be possible that you give a code example?

b) would be correct, if it meant a reference variable of the type "member inner class". but as i understand, they mean that the class is declared inside the interface, which is not possible.

c) correct. example:

private static void test(){
class C{};
C c = new C();
Object o = new Object(){};
}

d) same confusion about "top-level" and "nested" as in answer a). Because there is no such thing as a "nested top-level class", you could answer "no", because it can't contain a class that is nested and top-level. But on the other hand, the set containing only "nested top-level classes" is the empty set, and the empty set is contained in every other set, so "nested top-level classes" are also contained in the set of things possible to use in interfaces, so the answer "true" is also correct. So the answer can be true or false, both ansers are correct

David, where did you get the question from

And I hope the questions in the real exam don't need such a profund understanding of formal logic
[ March 03, 2006: Message edited by: Tilo Hemp ]
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pillai,

Thank you for the stuff.

After read some material about inner classes I think I've got over my mind about some of the below terms confusion.

Please correct if I'm wrong.

Regular Inner Classes
Used to represent inner classes that are not Static, Method Local, Anonymous.

Inner Classes
Used to represent classes that are created in line or inside another class or method. Same meaning of Regular Inner Classes.

Nested Classes
Same meaning of Inner Classes.

Top Level Classes
Same meaning of outer classes.

Top Level Nested Classes
Same meaning of Static Inner Classes

Top Level Inner Classes
 
reply
    Bookmark Topic Watch Topic
  • New Topic