> instance initializers ~ Online tutorial

instance initializers

Instance Initializers
An instance initializer declared in a class is executed when an instance of the class
is created , as specified in
InstanceInitializer:
Block
  • It is compile-time error if an instance initializer of a named class can throw a
    checked exception unless that exception or one of its supertypes is explicitly
    declared in the throws clause of each constructor of its class and the class has at
    least one explicitly declared constructor.
  • An instance initializer in an anonymous
    class ) can throw any exceptions.
  • The rules above distinguish between instance initializers in named and anonymous
    classes.
  • This distinction is deliberate. A given anonymous class is only
    instantiated at a single point in a program.
  • It is therefore possible to directly propagate information about what exceptions might be raised by an anonymous class’instance initializer to the surrounding expression.
  • Named classes, on the other hand, can be instantiated in many places. Therefore the only way to propagate information about what exceptions might be raised by an instance initializer of a named class is through the throws clauses of its constructors.

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: