Originally posted by Sravan Patti:
Hi,
I wanted to whether the use of variables in an interface is good practice or not. This question was asked in one of my interview.
Can also explain me the reason if it is NOT a good practice??
Thanks
Variables defined in an interface are constants, so they are implicitly public static final variables. They need to be initialized when they are defined.
I could see it being used for something like paymentType for a payment interface, but I would probably just put the constants for that in a base class, not in the interface.
This
thread discusses the same issue:
Java Ranch - Instance variables in interface Paul