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

variable declaration

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone tell me what all method declaration are valid amongs t the follpw ing
abstract int i;
a) abstract int i;
b] final int i;
c] final volatile int i;
d] public transient final i;
e] protected static final int i;
I think none is right b'coz when we declare final we need t o
intialize the variable there only
but why cant the variable be declared as abstract
???
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to intialize a final variable at time of declaration. It is called a blank final, but it needs to be initialized before it is used. The keyword abstract pertains to methods and classes. It implies that the method or class is incomplete.
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,
Please refer to the folowing code for my
clarification on the querry posted:

Hope this clarifies, so (b),(c),(d) and (e) are correct answers.
Ravindra Mohan.
[This message has been edited by Ravindra Mohan (edited May 08, 2001).]
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravindra,
c is incorrect since volatile can't be used with the final keyword. Try to compile it yourself. d is incorrect since there is no reference type. Try to compile them yourself. Transient can't be used with the final keyword either. At least that's what my compiler tells me.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sean Casey:
Ravindra,
c is incorrect since volatile can't be used with the final keyword. Try to compile it yourself. d is incorrect since there is no reference type. Try to compile them yourself. Transient can't be used with the final keyword either. At least that's what my compiler tells me.


Hi Sean,
You are right - final and volatile won't go together.
However the combination of transient and final is fine. The reason you got a compilation error is because the declaration shown in the question was wrong - try this:
public transient final int i = 10;
Take care,
- Lam -
 
Ravindra Mohan
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
Oops a correction from my earlier post, A VOLATILE variable cannot be declared as FINAL. I ran a code and the compiler told me the answer. I then looked for the same in the JLS which confirmed me the same. Please refer to JLS �8.3.1.4 volatile Fields at http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#36930
where this is clearly indicated :


A compile-time error occurs if a final variable is also declared volatile.


Hope this clears the issue.
Ravindra Mohan.
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic