This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

enthuware question doubt and smth else

 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a question in the Enthuware's mock:
Annonymous inner classes cannot be static.
And it's true regarding to enthuware answer.
So what about it:

OR


And my second doubt(that smth else ):


BUT:

IS OK

So there can be no blink static finals unless there is static initialization block. Blink static final can be initialized only at the time of referencing or inside the static initialization block. So static variables do not get their default values?

Correct me if I am wrong.

Whoa, quite a long post.
Thanks for replying.
 
Sheriff
Posts: 9704
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lukas Smith wrote:So static variables do not get their default values?



Class fields whether static or non-static, don't get a default value if they are final.

Also the example that you gave of static anonymous class is wrong, first of all the code won't compile as you closed Test class after m method so the declaration of T is invalid. Also that anonymous inner class is not static. You can try this to confirm

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't follow this - I have no problems compiling and running with a static anonymous inner class. Obviously though, I cannot invoke any new methods or members defined within that anonymous declaration; just what appears on the reference type.So why do Enthuware say an anonymous inner class cannot be static? I am worried I have a serious hole in my understanding.
 
Ankit Garg
Sheriff
Posts: 9704
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason in your code, the anonymous inner class is not static. Only the reference variable anonJunk is static. Static inner classes can declare static fields in them. But if you try to add static fields to your anonymous inner class, then it will show an error, that proves that your anonymous inner class is not static...
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, right. I get what is being meant now.

The anonymous inner declaration that cannot be static, but the reference can be. After all, unless you have an instance of that anonymous inner class, you have no way to reference it and thus no way to access any static members that you might try to put in there.

Makes sense.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, it is clear. Thanks.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic