• 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

Pl Validate the points

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body pl validate the follwoing points and correct me if I am wrong ? tahnks

Point#1: If you have a non final variable in a class the value must be assigned before constructor ends. If you have overloaded constructor then YOU HAVE to assign value to the final variable to all the overloaded constructors.

Point#2: If you have a final static variable then that variable must be assigned a value at the time declaration or in the static init block. If the value is not assigned at the time of declaration it must be assigned a value at lest before static init block ends. If you have more than one static init block then it is NOT NECESSASRY that you have to assign value in all static init block. If it is ok if you at least assign in one of the static init block

Point#3: Remember static variables also get default values like non static instance variables.

Point#4: Static variables can be referenced from non static context but non static variables CAN NOT be referenced from STATIC context.

Point#5: IF your class implements two different interfaces and both have same methods but one throws IOException and another throws FileNotFoundException. In this case if you have a call that implements both these interfaces then your implementation method can throw no exception or FileNotFoundException. FileNotFoundException is because out of the two IOException and FileNotFoundException , FileNotFoundException is lower level Exception.

Point#6: Instantiate init blocks will NOT get Executed by default. They will execute only when you create an instance; Where as static init blocks will get executed irrespective whether you create an instance or not . This is very important thing to remember.


Point#12: inner classes can not have static variables unless the inner class is declared static
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would modify points 1 and 12.

Point#1: If you have a non final variable in a class the value must be assigned before constructor ends. If you have overloaded constructor then YOU HAVE to assign value to the final variable to all the overloaded constructors.

I think what you meant to say here is blank final variable. If an instance variable is a blank final variable (a final variable declaration without an initializer), then that final variable must be definitely assigned by the end of every constructor or in an instance initializer block. If a non-final instance variable is not initialized by an initializer, initializer block, or a constructor, then it will be given a default value when an instance of the class is created.

Point#12: inner classes can not have static variables unless the inner class is declared static

Technically, the Java Language Specification calls a top-level nested class an inner class if it is not static. An inner class cannot contain a static member unless it is a final static member (a constant whose value can be resolved at compile-time).

Static nested classes can contain static members.
[ July 03, 2006: Message edited by: Keith Lynn ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic