access-modifiers

Access modifiers on interface members in C#

限于喜欢 提交于 2019-11-27 02:44:20
问题 I am getting a compile error from the following property. The error is: "The modifier 'public' is not valid for this item" public System.Collections.Specialized.StringDictionary IWorkItemControl.Properties { get { return properties; } set { properties = value; } } but if I remove the IWorkItemControl it compiles fine. Why am I getting this error and what is the difference of having / not having the interface name in the signature? 回答1: Explicit interface implementation does not let you

Is there anything like an Internal class in Java?

大憨熊 提交于 2019-11-27 01:28:03
问题 In C# you can mark a class as internal so that it is only accessible from within the same package. Is there anything similar in Java? 回答1: You can create package-private classes by omitting the security modifier (public, private) from the class's declaration. package com.sample; class MyPackagePrivateClass { ... } 回答2: Dropping the access modifier is similar to internal in C#. C# public class A { public static int X; internal static int Y; private static int Z; } internal class B { public

What is the use case for the (C# 7.2) “private protected” modifier?

浪尽此生 提交于 2019-11-27 00:32:57
问题 C# 7.2 introduces the private protected modifier. I've always protected access to fields with properties, allowing access via the Get/Set methods as I typically don't want the internal state of my object modified by anything other than my own class. I'm trying to understand why the C# language team have added this feature. After an extensive search on google, and reading and watching the 'what's new' media (I've watched the press release, details and video by Mads Torgerson), I am still none

Why can I access a derived private member function via a base class pointer to a derived object?

大憨熊 提交于 2019-11-27 00:28:09
问题 #include<iostream> using namespace std; class base { public: virtual void add() { cout << "hi"; } }; class derived : public base { private: void add() { cout << "bye"; } }; int main() { base *ptr; ptr = new derived; ptr->add(); return 0; } Output is bye I dont have a problem with how this is implemented. I understand you use vtables and the vtable of derived contains the address of the new add() function. But add() is private shouldn't compiler generate an error when I try to access it

“Private” (implementation) class in Python

断了今生、忘了曾经 提交于 2019-11-27 00:16:05
I am coding a small Python module composed of two parts: some functions defining a public interface, an implementation class used by the above functions, but which is not meaningful outside the module. At first, I decided to "hide" this implementation class by defining it inside the function using it, but this hampers readability and cannot be used if multiple functions reuse the same class. So, in addition to comments and docstrings, is there a mechanism to mark a class as "private" or "internal"? I am aware of the underscore mechanism, but as I understand it it only applies to variables,

Why can't we change access modifier while overriding methods in C#?

戏子无情 提交于 2019-11-26 22:20:46
In C#, we can not change access modifier while overriding a method from base class. e.g. Class Base { **protected** string foo() { return "Base"; } } Class Derived : Base { **public** override string foo() { return "Derived"; } } This is not valid in C#, It will give compile time error. I want to know the reason, why it's not allowed. Is there any technical problem or can it lead to something which is not consistent in terms of access restriction??? InBetween Changing the access modifier of a method in a derived type is pointless that's why it's not allowed: Case 1: Override with a more

C++ access modifier auto indentation in Visual Studio 2010 slowly driving me crazy - can it be changed?

你说的曾经没有我的故事 提交于 2019-11-26 22:04:48
问题 When programming C++ in Visual Studio, it insists on giving me these awful indentations on access modifiers - my condolences if anyone actually likes them this way ;) (a joke folks!) public class MyClass { public: MyClass(); ~MyClass(); int wowAnInt(); } Needless to say, I want this: public class MyClass { public: MyClass(); ~MyClass(); int wowAnInt(); } Is there any way to achieve this using anything (I've got ReSharper and Highlighter) or perhaps vanilla VS? 回答1: The closest you can get

Class is inaccessible due to its protection level

有些话、适合烂在心里 提交于 2019-11-26 22:00:40
问题 I have three classes. all are part of the same namespace. here are the basics of the three classes. //FBlock.cs namespace StubGenerator.PropGenerator { class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts { private List<Property> pProperties; private List<Method> pMethods; public FBlock(string aFBlockName) { pProperties = new List<Property>(); pMethods = new List<Method>(); } public Property

Static block in Java not executed

有些话、适合烂在心里 提交于 2019-11-26 21:37:24
class Test{ public static void main(String arg[]){ System.out.println("**MAIN METHOD"); System.out.println(Mno.VAL);//SOP(9090); System.out.println(Mno.VAL+100);//SOP(9190); } } class Mno{ final static int VAL=9090; static{ System.out.println("**STATIC BLOCK OF Mno\t:"+VAL); } } I know that a static block executed when class loaded. But in this case the instance variable inside class Mno is final , because of that the static block is not executing. Why is that so? And if I would remove the final , would it work fine? Which memory will be allocated first, the static final variable or the static

Default access modifier in C#

房东的猫 提交于 2019-11-26 21:33:29
问题 If I will create a new object like the following, which access modifier will it have by default? Object objectA = new Object(); 回答1: Any member will always have the most restrictive one available - so in this case the accessibility of objectA is private . (Assuming it's an instance variable. It makes no sense as a local variable, as they don't have any access rules as such.) So this: class Foo { Object objectA = new Object(); } is equivalent to this: internal class Foo { private Object