Hi, In Khalid Mughal's book question no. 4.26 on the page 130 goes like this: Which of these are not legal declarations within a class? Select all valid answers. (a) static int a ; (b) final Object[] fudge = { null } ; (c) abstract int t ; (d) native void sneeze() ; (e) final transient static private double PI = 3.14159265358979323846 ;
The correct answer given in the book is c. c is illegal, alright. But isn't e also illegal? In that book itself it mensioned that, Note that the transient modifier cannot be specified for static variables, as do not belong to objects. Here, PI is a static variable then how can it be transient?
Hi, Here is my opinion: Variables declared as transient don't get Serialized. I just tried an example of declaring a transient, static variable and it compiled fine. I also tried another example where i serialized(wrote to a file) a class with a static variable. And when I read back the data, I saw that the static variable diden't get serialized. So my conclusion is that: static int i; would be equivalent to static transient int i; Hope this helps Dominic
In regards to serialization, the result of having a variable defined as "static int blah" and "transient int blah" are exactly the same -- they won't be serialized. In regards to other things (like where the variable belongs to -- static vs. non-static) they're different. Having a variable marked as static transient is legal -- its just silly -- there's no contradiction in the behavior of the two modifiers, so why the heck would you do it? On the otherhand, having a method marked as abstract final is down right wrong -- the definitions are totally contradictory. final means the method cannot be overridden. abstract means the definition of the method was not complete and it MUST be overriden. does that help? Can you think of any other modifier combinations that are illegal? [ January 03, 2003: Message edited by: Jessica Sant ]
Just the easy and common one, abstract final Similar to this , abstract static final are illegal to a constructor. Even though I donot understand what is the problem with final(I did not tested it), constructors are final anyway. Ambapali
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.