簡體   English   中英

哪個可見性修飾符的可見性較低:受保護的還是內部的?

[英]Which visibility modifier has lesser visibility: Protected or Internal?

哪個可見性修飾符更寬松:受保護的還是內部的?

 internal var num = 18
        protected set   // throws an error at 'protected' showing: Setter visibility must be the same or less permissive than property visibility

我也試試這個:

 protected var num = 18
        internal set   // throws an error at 'internal' showing: Setter visibility must be the same or less permissive than property visibility

protected 表示該成員與標記為私有的成員具有相同的可見性,但它在子類中也是可見的。

internal 意味着該模塊內的任何客戶端看到聲明的 class 都會看到其內部成員。

它們沒有可比性; 兩者都不比另一個更寬容。

另一個模塊中的子類將看到protected的成員,但看不到internal

同一模塊中不相關的 class 將看到internal成員,但不受protected

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM