access-modifiers

Private class with Public method?

风流意气都作罢 提交于 2019-12-10 02:39:42
问题 Here is a piece of code: private class myClass { public static void Main() { } } 'or' private class myClass { public void method() { } } I know, first one will not work. And second one will. But why first is not working? Is there any specific reason for it? Actually looking for a solution in this perspective, thats why made it bold. Sorry 回答1: It would be meaningful in this scenario; you have a public class SomeClass , inside which you want to encapsulate some functionality that is only

Why C# does not support the intersection of Protected and Internal accessibility?

一世执手 提交于 2019-12-10 01:21:41
问题 protected internal: The union of protected and internal accessibility (this is less restrictive than protected or internal alone) The CLR has the concept of intersection of protected and internal accessibility, but C# does not support this. So my question is: What's the meaning of omitting this Access Modifier , is there a concrete reason? So why C# should not support it? 回答1: Update: C#7.2 is introducing this with the access modifier private protected , which seems wrong in a few ways but

When is the JVM bytecode access modifier flag 0x1000 (hex) “synthetic” set?

懵懂的女人 提交于 2019-12-09 15:41:57
问题 For some Java byte code parser project I read the JVM spec and figured out that the bit mask values of the Java virtual machine class file format access modifier fields are ACC_PUBLIC = 0x0001 ACC_FINAL = 0x0010 ACC_SUPER = 0x0020 # old invokespecial instruction semantics (Java 1.0x?) ACC_INTERFACE = 0x0200 ACC_ABSTRACT = 0x0400 ACC_SYNTHETIC = 0x1000 ACC_ANNOTATION = 0x2000 ACC_ENUM = 0x4000 Somehow I have no idea what 0x1000 is for. I saw it once in an inner class, but for all inner classes

Controlling read/write access to fields

百般思念 提交于 2019-12-09 07:42:28
Suppose that we would like to separate out the read and write access in an interface pattern as below. namespace accesspattern { namespace ReadOnly { public interface IA { double get_a(); } } namespace Writable { public interface IA : ReadOnly.IA { void set_a(double value); } } } This is easy to implement: namespace accesspattern { namespace ReadOnly { public class A : IA { protected double a; public double get_a() { return a; } } } namespace Writable { public class A : ReadOnly.A, IA { public void set_a(double value) { base.a = value; } } } } Suppose that we need another class which inherits

Access modifiers inside a private static nested class in Java

别来无恙 提交于 2019-12-09 03:04:50
问题 I have a "private static" nested class in Java. What is the significance of access modifiers for fields and methods inside this class? I've tried both public and private with no effect on my application. public class MyList<T>{ private static class Node{ // List node private Object item; private Node next; private Node prev; private Node(Node next){ this.next = next; } private static Node doStuff(){} } } 回答1: Two kinds of nested classes: 1. Static (nested class) and 2. Non-static (also called

Help to understand the issue with protected method

╄→尐↘猪︶ㄣ 提交于 2019-12-09 02:59:17
问题 I'm reading Sybex Complete Java 2 Certification Study Guide April 2005 (ISBN0782144195). This book is for java developers who wants to pass java certification. After a chapter about access modifiers (along with other modifiers) I found the following question (#17): True or false: If class Y extends class X, the two classes are in different packages, and class X has a protected method called abby(), then any instance of Y may call the abby() method of any other instance of Y. This question

Access a derived private member function from a base class pointer to a derived object [duplicate]

纵饮孤独 提交于 2019-12-08 17:12:16
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why can i access a derived private member function via a base class pointer to a derived object? #include <iostream> using namespace std; class B { public: virtual void fn1(void) {cout << "class B : fn one \n"; } virtual void fn2(void) {cout << "class B : fn two \n"; } }; class D: public B { void fn1(void) {cout << "class D : fn one \n"; } private: void fn2(void) {cout << "class D : fn two \n"; } }; int main

is_constructible and is_destructible unaffected by friend declarations

亡梦爱人 提交于 2019-12-08 16:47:29
问题 Clang and GCC appear not to honor friend declarations when evaluating std::is_constructible and std::is_destructible . Regarding `is_constructible, cppreference.com says: Access checks are performed as if from a context unrelated to T and any of the types in Args. Only the validity of the immediate context of the variable definition is considered. (The site doesn't explain how is_destructible deals with access checks, but access modifiers do affect the behavior of is_destructible in general,

.NET - how to make a class such that only one other specific class can instantiate it?

假装没事ソ 提交于 2019-12-08 16:24:26
问题 I'd like to have the following setup: class Descriptor { public string Name { get; private set; } public IList<Parameter> Parameters { get; private set; } // Set to ReadOnlyCollection private Descrtiptor() { } public Descriptor GetByName(string Name) { // Magic here, caching, loading, parsing, etc. } } class Parameter { public string Name { get; private set; } public string Valuie { get; private set; } } The whole structure will be read-only once loaded from an XML file. I'd like to make it

Error 1 Inconsistent accessibility: return type is less accessible than method

回眸只為那壹抹淺笑 提交于 2019-12-08 16:15:53
问题 When I'm building, VS show error. This is my code: public Composite buildComposite(ComboBox subs, ComboBox bas) { int count = 0; Composite a = new Composite(); if (subs.SelectedItem != null) { foreach (Substance d in listSubstance) { if (String.Compare(d.notation, subs.Text) == 0) { count++; a.subs = new Substance(d); break; } } } if (bas.SelectedItem != null) { foreach (Base g in listBase) { if (String.Compare(g.notation, bas.Text) == 0) { count++; a.bas = new Base(g); break; } } } if (count