access-modifiers

What is the difference between access modifiers in php? [closed]

我们两清 提交于 2019-11-29 13:06:31
I am totally confused with access modifiers in php. Is there any difference regarding memory utilization for access modifiers or only difference of accessibility..Please suggest. If i have following code: public Class Employee { public $emp_name='xyz'; protected $emp_phone='1234567891'; private $emp_code='101'; public function getName($name) { return 'Employee name is :' . $name; } protected function getPhone($ph) { return 'Employee contact number is :' . $ph; } private function getCode($id) { return 'Employee code is :' . $id; } $emp = new Employee(); $emp->getName($emp_name); $emp->getPhone(

Difference between “strict private” and “protected” Access Modifiers in Delphi?

一世执手 提交于 2019-11-29 11:15:57
问题 but I learn programming and after structured programming with Pascal language, I'm beginning to learn about OOP with Delphi. So, I don't really understand the difference between the strict private instruction and the protected one.. So here is my code, it's about a "bag" creation, it's just the introduction of my Delphi's lesson, teacher show us how we can create objects: uses SysUtils; Type Tbag= class (Tobject) strict private FcontenM : single; Fcontent : single; protected function

how do I iterate through internal properties in c#

谁说胖子不能爱 提交于 2019-11-29 10:54:08
问题 public class TestClass { public string property1 { get; set; } public string property2 { get; set; } internal string property3 { get; set; } internal string property4 { get; set; } internal string property5 { get; set; } } I can iterate through the properties with the following loop, but it only shows public properties. I need all the properties. foreach (PropertyInfo property in typeof(TestClass).GetProperties()) { //do something } 回答1: You need to specify that you don't just need the public

What is the purpose of access modifiers?

こ雲淡風輕ζ 提交于 2019-11-29 10:46:43
I know this applies to many languages, and not just Java, but that is the language I'm most familiar with. I understand what the modifiers do, and how to use them. I just want to know, why do we need them? Why can't every object be accessible, whether or not it needs to be? The reason becomes more apparent when you have to maintain a larger project. When a method or variable is public, you have to be careful when you make changes to it, because you never know which parts of the codebase rely on its exact behavior. But when a variable or method is private, you know that it is not used outside

Do access modifiers affect reflection also?

℡╲_俬逩灬. 提交于 2019-11-29 10:42:42
I always believe they did, but seeing some answers here make me doubt... Can I access private fields/properties/methods from outside a class through reflection? Yes you can access private fields via reflection. This is how a lot of ORMs go about populating an object without going through your properties (which will invoke business logic you might not have intended to be run on an object load). Access modifiers are not a form of security! You do, however, need extra permissions for accessing private/protected/internal fields/properties/methods from outside a class through reflection. Yes you

How do I make my controls inside a UserControl private?

元气小坏坏 提交于 2019-11-29 10:42:03
问题 I have a user control with a ComboBox and a TextBox. Everything is working great except I noticed that from my user control's instance object, I can access those two controls. They shouldn't be accessible except via my own exposed properties. 回答1: You can use the x:FieldModifier attribute on your controls, thusly: <TextBox x:Name="textBox1" x:FieldModifier="private" /> Interestingly the MSDN page for x:FieldModifier doesn't give "private" as a valid value for the attribute, but I've tested it

Java private field access possible when having a reference?

早过忘川 提交于 2019-11-29 09:58:06
I came across the following "strange" feature today - if you have a reference to an object from the class A in the body of the class A you can access the private fields of this object - i.e: public class Foo{ private int bar; private Foo foo; public void f() { if(foo.bar == bar) // foo.bar is visible here?! { // } } } Anyone has a good explanation about this? Access modifiers work at the class level, not at the instance level: all code in the same class can access private members of all instances of the class. Nothing particularly strange about it. It is intended to be this way. Citing the

internal abstract methods. Why would anyone have them?

回眸只為那壹抹淺笑 提交于 2019-11-29 09:18:52
I was doing some code review today and came across an old code written by some developer. It goes something like this public abstract class BaseControl { internal abstract void DoSomething(); } If you have a derived class within the same assembly, it would work public class DerivedControl : BaseControl { internal override void DoSomething() { } } But deriving the base class in a different assembly would give compile time error DerivedControl does not implement inherited abstract member 'BaseControl.DoSomething() That got me thinking. Why would anyone declare a method as internal abstract ? The

final variables are not functioning well in jshell

不问归期 提交于 2019-11-29 07:12:14
I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is some other way to work with final variables in jshell? While creating a final variable at the top-level

C# - Improving encapsulation of property in this example?

会有一股神秘感。 提交于 2019-11-29 06:26:42
I know of the error "The accessibility modifier of the set accessor must be more restrictive than the property or indexer". I also know the solution. Just not in this very specific case. Consider this example: internal virtual bool IsFocused { get { return isFocused; } protected set { isFocused = value; } } private bool isFocused; It shows the error. I just don't know why. How is "protected" not less accessible than internal? What would be the solution to this problem? I tried putting "internal protected" instead, without luck. protected allows an inherting class to access it while internal