This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The only kind of variables that you can define within an interface are "public static final" by default if you even specify it or not.
The answer to your question is in interface we can only define constants but no instance variables. The constants make sense in the interface as long as you those constant do specify something about the interface itself. But we can never have any instance variables or non-final and non-static and non-public variables in an interface declaration.
It is a good programming practice till those variables are related to interfaces themselves. As Zaheer quoted earlier, there is no ways that we can declare instance variables inside an interface, only constants. But declare only those contants which are interface specific, not related to something else. Otherwise it will really chew the clarity of your program up .
--Lost in preparation of SCJP and SCWCD--
"Start writing a new chapter, for if you live by the book you'll never make history." (Ben Sobel)
Joined: Jun 27, 2006
Thanks Zaheer Ahmed and Benz Zaidi. My doubt is clear now.