Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can anybody share time example of overriding, without using any dummy classes,

eg.
public class A
{

public int Add()
{
return 10;
}
}

public class B:A
{
public int Add()
{
return 11;
}
}
Main()
{
A obj = new B();

}

in which scenario we need to point object of child class need to bind to base class??
Posted
Comments
BillWoodruff 22-Nov-14 5:10am    
What do you mean by "real time" ?
Vivek S Kale 22-Nov-14 5:40am    
i think you don't know anything about C#
BillWoodruff 22-Nov-14 8:48am    
Of course, Dear, But, now that I know that I don't know, I can just ... well ... relax :)
Philippe Mori 22-Nov-14 12:54pm    
Obviously, it is you that don't known anything about C#. Here, you are talking about run-time behavioir which is different from real-time.

Real-time is something that is time-dépendent like streaming something from the web. In such case, there are timing constraint on the system to have playback without glitches.
Philippe Mori 22-Nov-14 12:56pm    
By the way, you should make the effort to use code formating for the code part.

1 solution

"without using any dummy classes" eh? OK...

Look at the standard ToString method:
It is implemented by the object class (from which all the other classes are derived) and it returns a string which is the full name of the object.
Most (but not all) derived classes override this to provide a string that is more relevant to the actual instance content: int overrides it to return a string representation of the integer value, bool overrides it to return either "true" or "false", and so on. If you create your own class, you can also override it:
C#
public class MyClass
    {
    public string Name { get; set; }
    public DateTime InsertDate { get; set; }
    public override string ToString()
        {
        return Name + " " + InsertDate.ToShortDateString();
        }
    }

When you call ToString on an instance, the system works out the highest level override and calls that instead of the default object implementation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900