Is it possible to override a private method by using Reflection in .NET 3.5?
If we want to access Private Field and method using Reflection we just need to call setAccessible(true) on the field or method object which you want to access. Class. getDeclaredField(String fieldName) or Class. getDeclaredFields() can be used to get private fields.
No, we cannot override private or static methods in Java. Private methods in Java are not visible to any other class which limits their scope to the class in which they are declared.
2) In Java, methods declared as private can never be overridden, they are in-fact bounded during compile time.
Answer: To access private method in C# programming of a class, we need to use reflection technique.
Well, it would need to be virtual
to be possible to override it (by writing a dynamic type that inherits from the class), and you can't have a private virtual
(it makes no sense). You could perhaps override an internal virtual
, but I suspect even this may hit security issues. So ultimately, I'd say no.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With