Monday, 11 July 2016

What is function overloading? How C# supports dynamic polymorphism? sealed? Is operator overloading supported in C#?

You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.

Dynamic polymorphism is implemented by abstract classes and virtual functions

When a class is declared sealed, it cannot be inherited.
How will you create sealed abstract class in C#?
No! It can not be created as abstract classes cannot be declared sealed
What are virtual functions in C#?
When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could be implemented differently in different inherited class and the call to these functions will be decided at runtime.

class Projector
{
  public static void DisplayString( string str )
  {
    System.Console.WriteLine( str );
  } 
  public static void DisplayInteger( int number )
  {
    System.Console.WriteLine( number);
  } 
  public static void Main()
  {
    DisplayString( "Hello" );
    DisplayInteger( 1234 );
  }
}



Is operator overloading supported in C#?

You can redefine or overload most of the built-in operators available in C#. Thus a programmer can use operators with user-defined types as well.
Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined. Similar to any other function, an overloaded operator has a return type and a parameter list.

No comments:

Post a Comment