Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are interface variables public

Tags:

java

interface

I know that Java interface variables are by default public static and final.

I understood why they are static and final by seeing this discussion

But I didn't reason behind why interface variables are public by default.

If any one knows the reason behind why interface variables are always public and why can not we have a protected or default variables in an interface, kindly explain me.

Kindly don't ask me to google for it because I have been googling for it for more than two hours and there is no clear explanation from any site about why the variables are public by default.

I have seen the below blog also but there is no clear info about my query.

like image 404
Jagadeesh Avatar asked Nov 02 '25 18:11

Jagadeesh


1 Answers

Interfaces are "behaviour blueprints". Unlike classes, they shouldn't (and do not) have states.

Since instance variables represents the state of an object, interfaces do not have instance variables (being them private or public). And since private static variables represent the state of a class, they don't have private static variables either.

like image 187
javatutorial Avatar answered Nov 04 '25 08:11

javatutorial



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!