• 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

static final?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which answer is correct.
class Widget
{
static int MAX; //1
static final String CLASS_GUID; // 2
Widget()
{
//3
}
Widget(int k)
{
//4
}
}
1.Add the following line just before //1 {MAX=111;CLASS_GUID="SS";}
2.Modify lines //1 and //2 as static int MAX=111;static final String CLASS_GUID="SS";
3.Add the following line just after //2 static {MAX=111;CLASS_GUID="SS";}

It is a question from enthuware software. It says the answer is 1
But I got the error with the option 1.
I believe anser is 2. Please advise
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. you are right.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thing answer 2 & 3 both are correct
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nilesh,

i think answer 3 is not correct. I believe you need to intitialize final variable when you declare.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Number 1 is wrong because you can't assign a value to MAX and CLASS_GUID without first declaring them.

Number 2 and 3 are right. I have done lots of times the Rules Roundup game and there is a question/answer that it says you can assign the value to a final variable after the declaration without problem.
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Number 2 and 3 are right. I have done lots of times the Rules Roundup game and there is a question/answer that it says you can assign the value to a final variable after the declaration without problem.



To be more precise, if you have not initialized static final variable at the time of declaration, then how late you can initialize it?

Initialization in static initialization block is must in that case.

Similarly if variable is non-static and final, then they must be initialized in every overloaded constructor.

Naseem
[ August 10, 2006: Message edited by: Naseem Khan ]
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic