aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enthuware question doubt and smth else Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enthuware question doubt and smth else" Watch "enthuware question doubt and smth else" New topic
Author

enthuware question doubt and smth else

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

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.

SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

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



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
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.


SCJP6
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

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

Joined: Jun 09, 2009
Posts: 327
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

Joined: Apr 20, 2009
Posts: 804
    
    1

OK, it is clear. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enthuware question doubt and smth else