[英]Is this code valid? Can I have a private field in a class without public getters and setters?
這不是我的代碼,我只是在研究語言是如何工作的,什么是允許的,什么是不允許的,所以我正在從不同的例子中學習。 在這種情況下,class B 是正確的嗎? ...
[英]Is this code valid? Can I have a private field in a class without public getters and setters?
這不是我的代碼,我只是在研究語言是如何工作的,什么是允許的,什么是不允許的,所以我正在從不同的例子中學習。 在這種情況下,class B 是正確的嗎? ...
[英]Lack of access to class properties
我有一個具有多個屬性的秒表方法,我希望沒有人能夠從 class 之外訪問它們,我將它們設為私有,但仍然可以訪問它們並且可以更改它們的值。 我該怎么辦? ...
[英]How to access to a function whose access modifier is protected and exists in a class that inherits from another class in c#?
如何訪問 function,其訪問修飾符受保護並存在於 class 中,該 class 繼承自 c# 中的另一個 class? ...
[英]Ignore access modifiers while compilation Java
是否可以在編譯期間忽略 java 訪問修飾符? (除了 javac 插件)我有一個 java 代理,它應該在運行時影響修飾符。 我有興趣嘗試通過欺騙(或以某種方式要求它不要查看修飾符)編譯器來編譯文件。 ...
[英]What is the default access modifier for a variable in Unity, and why?
這是一個比看起來更復雜的問題。 我能找到的每個討論訪問修飾符的 Unity 視頻和教程都告訴我“ private是 C# 中成員變量的默認訪問修飾符”,但根據 C# 文檔,默認訪問修飾符應該是internal 。 例如,這個官方視頻,時間戳記到演講者這樣說的時間點: https://youtu.b ...
[英]Data privacy and Access Modifiers java
我目前正在進行一個項目,我有點進退兩難。 假設我有一個名為 A 的 class。在 class A 中,有一個私有嵌套的 class 名為 B。然后我創建了另一個名為 class 的繼承 A 的 class。我是否需要保護 B 以便 8810375865863 可以訪問它? 或者是否有另一種方法可 ...
[英]What did the author of the book mean?
另一方面,private 關鍵字意味着除了您(類型的創建者)在該類型的內部方法中之外,沒有人可以訪問該元素。 我真的不明白突出顯示的文本中發生了什么。 ...
[英]private modifier in php doesn' work like expected
我有這個 class 在這里我可以毫無問題地使用私人價格嗎? 結果是這樣的: 我無法理解如何為私有變量賦值? ...
[英]How to make a property of a class accessible to another certain class without making it public?
在下面的代碼中,我想在LinkStack.Pop()中訪問StackElement.below ,所以我不能將StackElement.below裝飾為私有。 但是,我也不想將其公開,因為如果任何其他 class 可以訪問該屬性,則不安全。 那我該怎么辦? 提前致謝。 ...
[英]Struggling to understand the effects of access modifiers and the keyword "static"
我對 Java 很陌生。 我剛剛寫了一個小例子來觀察訪問修飾符的效果。 也許代碼沒有多大意義,因為我只是在測試。 第一個代碼片段如下所示:class Tet { static double a; double b; public Tet(double a, double b) ...
[英]How to restrict access privilege between two classes in java?
我有兩個類Player和Gamepublic class Player { private List<String> cards; public Player(){ cards = new ArrayList<String>(); ...
[英]access protected members of another instance in derived class
即使我在一個派生類中應該讓我訪問派生的受保護成員,但我得到了錯誤 “無法從此處訪問受保護的方法‘BaseMethod’” 當試圖調用other.BaseMethod(); . 我可以在不公開BaseMethod的情況下解決這個問題嗎? 我也無法使方法internal ,因為Base和De ...
[英]Android Studio: "attempting to assign weaker access privileges" error on Room Database implementation
我正在嘗試實現房間數據庫,我已經完成了官方網站上的步驟,“AppDatabase.java”文件是這樣的: 以及我用於房間的依賴項: 它在這里返回 2 個錯誤: 它在“Chipmunk”版本之前工作(在“Bumblebee”中工作),但它開始拋出這些錯誤。 這里發生了什么? ...
[英]Why a subclass in a different package is unable to access the protected fields of its superclass in another package through superclass instance?
可以從不同包中的子類訪問類的受保護字段,那么為什么代碼顯示“字段 Ax 不可見?” ...
[英]Why come output as 9 when I call to display method using getModifiers() method in (Reflection of Java Methods)?
這是Dog類,它包括display和makesound方法 這是主課。 當我使用getModifiers方法調用 make sound 方法時,輸出為 2,但 display 方法輸出為 9。這是為什么呢? 我認為顯示方法有 3 個訪問修改。 但是Modifier.toString(modi ...
[英]Kotlin inner/nested class instantiable only from parent
是否可以將以下 Java 片段翻譯成 Kotlin? 維護訪問修飾符提供的保證public class Outer { public Inner newInner() { return new Inner(); } public static class ...
[英]why to make a classes or attributes private?
我想問一下為什么我應該將 class 設為私有或將屬性設為私有我保護它不受什么影響? 我認為只有應用程序中的用戶可以使用的屬性來提供或更新它們(如(郵件、密碼或年齡))才應該是私有的,但他不會要求填寫的任何其他屬性都可以公開嗎? 是真的嗎? ...
[英]Acces private static member variable in namespace from another class C++
我有個問題。 在下面的示例中,有一個名為private_b的 class A內部命名空間a的私有成員變量 static。 然后我試圖從 class B訪問該變量,我已聲明它是 class A的friend ,但它不起作用,編譯錯誤來自 GCC: 錯誤:“B* a::A::private_b”在此上 ...
[英]spread operator for object containing readonly
我的樣本 class:class Foo { private static counter = 1; readonly id: number; constructor() { this.id = Foo.counter++; } } 我有兩個選擇: 讓構造函數接受另一個 ...
[英]Why does java force all interface members to be public?
假設我有一個包含以下內容的文件test.java :interface IA { void f(); } class A implements IA { public void f() { System.out.println("test"); } } 如文檔中所述,默認情 ...