Why when a method is implemented from an interface, should it be declared as public ?
1 answer
Because the interface is designed to ensure that there are public methods that external users can use for the class.
And how these public methods will be implemented, including what they will use private methods - this is your own business.
- It is worth adding that you can create an object and assign it to an interface type variable and this should guarantee the operation of all the methods declared in the interface. For example:
IЛетающий летающий = new Самолет(); летающий.Лети();IЛетающий летающий = new Самолет(); летающий.Лети();- Andrei NOP - Not sure about java, but with C # there are still obvious implementations of the interface, when the method declared by the interface can only be called explicitly by casting the object to the interface type:
|