Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it true that if you don't specify an access modifier for an interface, that interface will have default access

I'm reading SCJP by Kathy Sierra and Bert Bates and it says on pg. 21 that "The public modifier is required if you want the interface to have public rather than default access". Is this true? If yes, then the interface methods (which are always public) only accessible if the interface is in the same package of the implementing class...? Since that is the meaning of the default access modifier...I'm a bit confused on this.

like image 669
user1142130 Avatar asked Jan 27 '26 16:01

user1142130


1 Answers

Is it true that if you don't specify an access modifier for an interface, that interface will have default access?

Yes that is true. Java types/fields/methods (in class) have package-level access if access modifier is not specified. Members defined in inteface type are public by-default.

Read tutorial - Controlling Access to Members of a Class.

like image 86
KV Prajapati Avatar answered Jan 29 '26 04:01

KV Prajapati



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!