Java Reference
In-Depth Information
private static Engine newEngine() {
try {
return (Engine) engineClass.newInstance();
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
}
}
public Car() { }
}
In summary, instance initializers run before constructor bodies. Any exceptions thrown by instance
initializers propagate to constructors. If initializers throw checked exceptions, constructors must be
declared to throw them too, but this should be avoided, because it is confusing. Finally, beware of
infinite recursion when designing classes whose instances contain other instances of the same class.
< Day Day Up >
 
 
Search WWH ::




Custom Search