access-modifiers

Public and Internal members in an Internal class?

Ok, so this may be a bit of a silly question, and there's certainly the obvious answer, but I was curious if I've missed any subtleties here. Is there any difference in terms of visibility/usability between a public member declared in an internal class and an internal member declared in an internal class? i.e. between internal class F...

error: 'void Base::output()' is protected within this context

I'm confused about the errors generated by the following code. In Derived::doStuff, I can access Base::output directly by calling it. Why can't I create a pointer to output() in the same context that I can call output()? (I thought protected / private governed whether you could use a name in a specific context, but apparently that is i...

How do Java public/private and static modifiers affect multiple variables declared on one line?

Are the following equivalent? private static boolean readAllFiles = false,readAllDirs = false; private static boolean readAllFiles = false; private static boolean readAllDirs = false; And if so, do they still have the same modifiers with different values? private static boolean readAllFiles = false,readAllDirs = true; ...

Force the use of interface instead of concrete implementation in declaration (.NET)

In C++, you can do the following: class base_class { public: virtual void do_something() = 0; }; class derived_class : public base_class { private: virtual void do_something() { std::cout << "do_something() called"; } }; The derived_class overrides the method do_something() and makes it private. The effect is...

Outside classes accessing package-private methods

Suppose I have a class in my package org.jake and it has a method with default access (no modifier). Then the method is visible inside the package only. However, when someone receives the jar of my framework, what is to stop them from writing a new class, declaring its package as org.jake, and using my supposedly invisible method? In ...

PHP5: restrict access to function to certain classes

Is there a way in PHP5 to only allow a certain class or set of classes to call a particular function? For example, let's say I have three classes ("Foo", "Bar", and "Baz"), all with similarly-named methods, and I want Bar to be able to call Foo::foo() but deny Baz the ability to make that call: class Foo { static function foo() { pr...

Why can't my subclass access a protected variable of its superclass, when it's in a different package?

I have an abstract class, relation in package database.relation and a subclass of it, Join, in package database.operations. relation has a protected member named mStructure. In Join: public Join(final Relation relLeft, final Relation relRight) { super(); mRelLeft = relLeft; mRelRight = relRight; mStruct...

VB.NET Visual Inheritance: Friend VS Protected

Why is it that some components/controls will not be inherited visually in a child form if they are declared with the access modifier Friend vs when they are declared with Protected. For example, I've got a DataSet object in my Parent Form that was initially "Friend" (I drag and dropped it to the form, so it was shown as a control in th...

Should you make use of private, protected, and public modifiers in Ruby?

I come from more of a C# background yet am learning Ruby in my spare time. Given classes, it is possible to make their methods private, public (default) or protected. While I understand their usage, is it typical for Ruby code to make use of such modifiers, despite being a dynamic language, in which the user can easily override access? ...

accessing protected method in other package?

If I say class A{ } then it implicitly inherits Object class.So I am having the class as below: class A{ protected Object clone(){ } /// Here i am not overridning //All the other methods (toString/wait/notify/notifyAll/getClass) } Now Why cant I access the clone() method in Class B which is in the same packag...

Do access modifiers work for static class functions?

I just came across code that had protected static class functions, as in: class C { ... protected: static int fun() { ... } }; I got curious if static class functions could have access modifiers and what would it mean? Since they are class globals and not pre-instance. Thanks, Boda Cydo. ...

What kind of access modifiers can be applied to a class?

After a little research I've determined that the only access modifiers which you can apply to classes are: public - available in any assembly internal - available only in the current assembly but the error message below seems to imply that if a class is not defined in a namespace that it could be defined as private, protected, or pro...

Modifier System C#

I am trying to figure out a system that can easily modify objects on the fly. here is an example, Lets say I have an Entity2D that inherits from Entity. Entity2D has a Position property. Now I have a class called ModifyPosition that inherits from Modifier. Here is some code public class Entity { /// <summary> /// Applies the modifier...

Are there any reasons to use private properties in C#?

I just realized that the C# property construct can also be used with a private access modifier: private string Password { get; set; } Although this is technically interesting, I can't imagine when I would use it since a private field involves even less ceremony: private string _password; and I can't imagine when I would ever need t...

public, protected, private

Hey, Take a look at this code: #include <iostream> using namespace std; class A { private: int privatefield; protected: int protectedfield; public: int publicfield; }; class B: private A { private: A a; public: void test() { cout << this->publicfield << this->protectedfield << endl; } void tes...

Java problem: multiple classes in a single file

Hi all, I am not able to understand why this code doesnt compile : class A { public static void main(String[] args) { System.out.println("hi"); } } private class B { int a; } I am saving the contents in a file named A.java - and I get an error : modifier private not allowed here // where I have def...

Why is the sealed keyword not included in the list of access modifiers?

I think sealed should be included in the list of access modifiers in C# language. Can somebody tell the reason why it has been excluded? ...

Class is inaccessible due to its protection level

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<Prope...

Default access modifier in C#

if I will create new object like this: Object objectA = new Object(); Which access modifier it will have by default? ...

Access Modifiers ... Why?

Ok so I was just thinking to myself why do programmers stress so much when it comes down to Access Modifiers within OOP. Lets take this code for example / PHP! class StackOverflow { private var $web_address; public function setWebAddress(){/*...*/} } Because web_address is private it cannot be changed by $object->web_address...