Why we make a Logger object in class as static final?


static final Logger logger=Logger.getLogger (Sample. class);


A class can have both static and instance methods. Logging statements are required in both methods.
 If we make Logger object as non-static then it can be used in only instance methods but not in static methods. So, we make Logger object as static. In order to use it in both static and instance methods of class.

We make a Logger object as final because, we definitely need one Logger object per one Class. And should not be changeable.so, we make it as final.

0 comments:

Post a Comment