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

Anonymous class concept

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What modifiers we can use with anonymous classes:
A. public
B. private
C. protected
D. abstract
I don't know about anonymous classes much please help me.
Regards
Farhan
 
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 Farhan,
I would say that an anonymous class can be any of the first three:
A, B, or C
The last one is incorrect because abstract means that a subclass will provide some implementation and since we are dealing with anonymous classes (no names) it is impossible to subclass them!
Regards,
Manfred.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
Can you imagine a reason why you would want to change the access modifier on an anonymous class from the default? You will only be using it once and you wont know it's name (poor thing).

Interesting question though!
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
None. An anonymous class is created inside a method so it only has method scope. And where would you put the class modifier?
 
Farhan Tariq
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys!
I agree with Jon and Thomas. They provide good reason. I have another doubt about this type that whether or not the impact of modifiers(coderanch, protected, private) of enclosing method, occurs on the anonymous class. e.g if we have a method "private void amethod(){}" and we have an anonymous classin it , so is there any impact of the private modifier of the enclosing method, means when we change that modifier to public or protected.
Regards
Farhan
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Farhan Tariq:
Hi guys!
I agree with Jon and Thomas. They provide good reason. I have another doubt about this type that whether or not the impact of modifiers(coderanch, protected, private) of enclosing method, occurs on the anonymous class. e.g if we have a method "private void amethod(){}" and we have an anonymous classin it , so is there any impact of the private modifier of the enclosing method, means when we change that modifier to public or protected.
Regards
Farhan


well as anonymous classes have only method scope they are restricted to the method. However like any other object if u pass this reference out then it can be accessed from any other place.
Hope this helps
Anand
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per Khalid Mughall Inner classes and ofcourse Anonymous classes can not have any accessibility modifier. I have also tested this fact.
Hope this helps...
Adeeshwar
Experience tells you what to do; confidence allows you to do it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic