Why can’t a class or an interface receive private or protected access modifiers?

private means “only visible within the enclosing class”. protected means “only visible within the enclosing class and any subclasses, and also anywhere in the enclosing class’s package”. private, therefore, has no meaning when applied to a top-level class; the same goes for the first part of the definition of protected. The second part of protected … Read more

how do I iterate through internal properties in c#

You need to specify that you don’t just need the public properties, using the overload accepting BindingFlags: foreach (PropertyInfo property in typeof(TestClass) .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { //do something } Add BindingFlags.Static if you want to include static properties. The parameterless overload only returns public properties.

Protected Classes in .NET

Yes, you just cannot make them top level classes, they must be inner classes public class Outer { protected class Foo { } } This is fine, it means that the only classes allowed to see Foo are sub classes of Outer class X { // ‘Outer.Foo’ is inaccessible due to its protection level private … Read more

Deletion of copy-ctor & copy-assignment – public, private or protected?

what is the right place to do it – in the public, private or protected section of the class? I would put them in the public section. This is because deleting a constructor or an assignment operator is orthogonal to making them private / protected; and when these aren’t deleted, they are public by default. … Read more

Why can’t I use protected constructors outside the package? [duplicate]

Usually protected means only accessible to subclasses or classes in the same package. However here are the rules for constructors from the JLS: 6.6.2.2. Qualified Access to a protected Constructor Let C be the class in which a protected constructor is declared and let S be the innermost class in whose declaration the use of … Read more

Protected method in python [duplicate]

Python does not support access protection as C++/Java/C# does. Everything is public. The motto is, “We’re all adults here.” Document your classes, and insist that your collaborators read and follow the documentation. The culture in Python is that names starting with underscores mean, “don’t use these unless you really know you should.” You might choose … Read more

difference between protected and package-private access modifiers in Java? [duplicate]

The first answer is basically correct – protected members can be accessed by classes from the same package subclasses of the declaring class from other packages However, there is a little trick: 6.6.2 Details on protected Access A protected member or constructor of an object may be accessed from outside the package in which it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)