• 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

tipsmart mock

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q8. What will be the result of compiling following code
public class MyClass
public class MyClass
{
final int i ;
public static void main(String[] arguments)
{
System.out.println(new MyClass().i);
}
}
gives compile time error
why???
 
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 Sona,
The error is on account of the fact that final values need to
be expilitilely initialised before using it. Please note
that final values are not set to their default values.
You may checkout the similar discussion at JavaRanch.
Ravindra Mohan.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
compilation error is because a blank final variable (i.e a final variable which has not been initialized) must be initialized once before it is used or must be initialized in every constructor
hope that helps
Samith.P.Nambiar
-----------------------------
harder u try luckier u get
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic