Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Anonymous class declared as static

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
One doubt please
Can anonymous class be declared as static
please explein with examples!!!


thnx
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can have a static class member pointing to an anonymous class as below:



I think this was what you wanted. Please let me know if I understood wrongly.
 
Daksh Mital
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No sir...
What i meant to ask was that
whether an anonymous class can be a static class or non-static class

What are the criteria that decides that the following anonymous class in static or non-static...

I am reading Khalid mughal book .
In the chapter 7 under section of anonymous class he is referencing static and non static class..
I wanted an explanation on that..

Thnx anyways..

ciao!!
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static modifier applies to class members. I think an anonymous class is not a class member in that sense and hence we cannot talk in terms of it being static/non-static. It is always defined in a method/block. This is similar to something like Local variables not being static.
[ August 21, 2007: Message edited by: Satya Maheshwari ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satya Maheshwari:
Static modifier applies to class members. I think an anonymous class is not a class member in that sense and hence we cannot talk in terms of it being static/non-static. It is always defined in a method/block. This is similar to something like Local variables not being static.


static does not only apply to class members. You can also make static nested classes:

But there is no way to make a static anonymous class.
[ August 21, 2007: Message edited by: Jesper Young ]
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jesper

Thanks for correcting. But I had one related question, is'nt a static inner class a class member too just like member methods and variables.
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic