oop
What does Protected Internal mean in .Net [duplicate]
It’s a confusing one. protected means “only this class and derived classes”. internal means “only classes in this assembly”. protected internal means “protected OR internal” (any class in the same assembly, or any derived class – even if it is in a different assembly). i.e. it does not mean “protected AND internal” (only derived classes … Read more
Why can’t a class have same name for a function and a data member?
Suppose you want to take the address of the member-function size(), then you would write this: auto address = &demo::size; But it could be very well be the address of the member-data size as well. Ambiguous situation. Hence, it is disallowed by the language specification. That is not to say that it was impossible for … Read more
Why does StringBuffer/StringBuilder not override equals or hashCode?
Because StringBuffer is mutable, and its primary use is for constructing strings. If you want to compare content, call StringBuffer#toString() and compare the returned value. It is not generally useful to override hashCode() for mutable objects, since modifying such an object that is used as a key in a HashMap could cause the stored value … Read more
Using “Base” in a Class Name
I tend to add a Base suffix to the name of the base class only if it exists from technical perspective (to share some code), and doesn’t really constitute any usable class on its own (so all of these classes are abstract). These are quite rare cases though, and should be avoided just as Helper … Read more
Default properties in VB.NET?
Well, the .NET framework does have a notion of a default member. Key ingredients are the DefaultMemberAttribute class and Type.GetDefaultMembers(). In VB.NET, specifying the default member is part of the language syntax: Public Class Sample Private mValue As Integer Default Public ReadOnly Property Test(ByVal index As Integer) As Integer Get Return index End Get End … Read more
How can a derived class invoke private method of base class?
Because you defined the main method in PrivateOverride class. If you put the main method in Derived class, it would not compile, because .f() would not be visible there. po.f() call in PrivateOverride class is not a polymorphism, because the f() in PrivateOverride class is private, so f() in Derived class is not overriden.
What’s the deal with Java’s public fields?
Public fields expose the representation of an object to its callers, i.e. if the representation has to change, so do the callers. By encapsulating the representation, you can enforce how callers interact with it, and can change that representation without having to modify the callers provided the public api is unchanged. In any non-trivial program, … Read more