• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classes(inner, nested)

 
Aru
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can someone explain & Answer the following ?
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.

Thx in Advance.
Aruna
 
Uvnik Gupta
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All are true !!!
Correct me if I am wrong.
 
rajsim
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>e) A static method can contain a nested top-level class.
a method can only contain local or anonymous class
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also-
b) An interface can contain a member inner class.
No, an interface can only contain a static member class, formerly known as a top-level nested class (which is probably what answer a) was trying to refer to). All classes defined in an interface are implicitly static and public.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone let me know which are the right answers.
thankx
shanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Rahul and I explained what's wrong with e and b, the remaining answers are correct:
a, c, d
 
kevin jia
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I don't agree your point. Although a member inner class within an interface is implicitly public and static, but in forms it is a member, how could we call this form of inner class.
For example:
public interface A {
class inner { }
}
There is a problem of nature language, but not Java language.
Originally posted by Jim Yingst:
Since Rahul and I explained what's wrong with e and b, the remaining answers are correct:
a, c, d

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic