Questions tagged [method-hiding]

94 questions
222
votes
11 answers

C# - Keyword usage virtual+override vs. new

What are differences between declaring a method in a base type "virtual" and then overriding it in a child type using the "override" keyword as opposed to simply using the "new" keyword when declaring the matching method in the child type?
i3ensays
  • 2,804
  • 3
  • 19
  • 23
101
votes
17 answers

Overriding vs Hiding Java - Confused

I'm confused on how overriding differs from hiding in Java. Can anyone provide more details on how these differ? I read the Java Tutorial but the sample code still left me confused. To be more clear, I understand overriding well. My issue is that I…
Lostlinkpr
  • 1,453
  • 2
  • 12
  • 13
75
votes
8 answers

What is method hiding in Java? Even the JavaDoc explanation is confusing

Javadoc says: the version of the hidden method that gets invoked is the one in the superclass, and the version of the overridden method that gets invoked is the one in the subclass. doesn't ring a bell to me. Any clear example showing the meaning…
JATMON
  • 1,000
  • 1
  • 8
  • 14
63
votes
3 answers

Overriding vs method hiding

I am a bit confused about overriding vs. hiding a method in C#. Practical uses of each would also be appreciated, as well as an explanation for when one would use each. I am confused about overriding - why do we override? What I have learnt so far…
NoviceToDotNet
  • 10,387
  • 36
  • 112
  • 166
34
votes
5 answers

What are the differences between overriding virtual functions and hiding non-virtual functions?

Given the following code fragment, what are the differences in the function calls? What is function hiding? What is function overriding? How do they relate to function overloads? What is the difference between the two? I couldn't find a good…
Jed Schaaf
  • 1,045
  • 1
  • 10
  • 19
13
votes
4 answers

How method hiding works in C#? (Part Two)

The following program prints A:C(A,B) B:C(A,B) (as it should) public interface I { string A(); } public class C : I { public string A() { return "A"; } public string B() { return "B"; } } public class…
Prankster
  • 4,031
  • 5
  • 33
  • 44
9
votes
1 answer

What scenarios does it make sense to use "method hiding"?

Possible Duplicate: method hiding in c# with a valid example .why is it implemented in the framework.? what is the Real world advantage.? I am wondering how method hiding could be useful in c# ? If you dive into the concept ,you can find that…
siamak
  • 669
  • 1
  • 10
  • 28
8
votes
3 answers

Hiding methods of superclass

I've read the Overriding and Hiding Methods tutorial. And from that, I gathered the following: If a subclass defines a class method with the same signature as a class method in the superclass, the method in the subclass hides the one in the…
mrkhrts
  • 829
  • 7
  • 17
8
votes
5 answers

How method hiding works in C#?

Why the following program prints B B (as it should) public class A { public void Print() { Console.WriteLine("A"); } } public class B : A { public new void Print() { …
Prankster
  • 4,031
  • 5
  • 33
  • 44
7
votes
2 answers

getDeclaredMethods() and hidden super class static method

According to http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html#getDeclaredMethods%28%29, Class.getDeclaredMethods() should only include methods "declared by the class". However, I am getting some pretty surprising results with…
RAY
  • 6,810
  • 6
  • 40
  • 67
6
votes
2 answers

Are there any legitimate reasons to hide static methods?

Possible Duplicate: Why doesn't Java allow overriding of static methods? Is there any legitimate reason why one would want a derived class to override hide a static method of the base class?
Saket
  • 45,521
  • 12
  • 59
  • 79
5
votes
2 answers

Java - Hiding Overriding and the modifier final

I couldn't find a question like mine, so I hope it's not a duplicate one. Again it's about overriding and hiding. I think - but I might be wrong - I understood both. The following code behaves as expected, both methods have been hidden. method1…
whoCares
  • 53
  • 6
5
votes
1 answer

Why does Java restrict the access modifier of a hiding method

When hiding a static field, there's no restriction on what access level does the field have in subclass, it can be even non-static and of other data type. On the other side, when hiding a static method, the static method from subclass that hides the…
Bax
  • 4,260
  • 5
  • 43
  • 65
5
votes
1 answer

Ruby hiding vs overriding

I've just learned that in Java there is a distinction between overriding and hiding (static methods are hidden not overriden) which implies that Java uses both early and late binding. Is there something similar to method hiding or it does it just…
Javier
  • 61
  • 4
5
votes
8 answers

Why does not call parent method when we don't use method hiding?

Consider this code: internal class Program { private static void Main(string[] args) { var student = new Student(); student.ShowInfo(); //output --> "I am Student" } } public class Person …
Yazdan Bayati
  • 184
  • 1
  • 2
  • 6
1
2 3 4 5 6 7