Is there a reason you can not define the access modifier on a method or in an interface?

后端 未结 5 1997
悲哀的现实
悲哀的现实 2020-12-21 00:23

The responsibility of the visibility of a method is relegated to the class that implements the interface.

public interface IMyInterface
{
  bool GetMyInfo(st         


        
5条回答
  •  失恋的感觉
    2020-12-21 01:07

    The interface defines a contract between an object and clients that call its members. A private method cannot be accessed by any other objects so it doesn't make sense to add it to the interface. All members of an interface are considered public for this reason.

提交回复
热议问题