• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mughal Q4.26

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you think of any other modifier combinations that are illegal?
private abstract
abstract static
abstract native
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic