wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mughal Q4.26 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mughal Q4.26" Watch "Mughal Q4.26" New topic

Mughal Q4.26

Prosenjit Banerjee
Ranch Hand

Joined: Dec 18, 2002
Posts: 102
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?

Always say the TRUTH only
Dominic Paquette
Ranch Hand

Joined: Dec 13, 2002
Posts: 64
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
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

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 ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Can you think of any other modifier combinations that are illegal?
private abstract
abstract static
abstract native

[Blog] [Blogroll] [My Reviews] My Linked In
Ambapali Pal
Ranch Hand

Joined: Dec 17, 2002
Posts: 47
Just the easy and common one,
abstract final
Similar to this ,
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Mughal Q4.26
It's not a secret anymore!