Classes can inherit from another class. This is accomplished by putting a colon after the class name when declaring the class, and naming the class to inherit from—the base class—after the colon
using System;
namespace Tutorial { public class Parent { string parentString; public Parent() // Constructor { Console.WriteLine("Parent Constructor."); } public Parent(string myString) // Constructor takes "myString" as parameter. { parentString = myString; // Assigns parameter to parentString Console.WriteLine(parentString); } public void print() { Console.WriteLine("I'm a Parent Class."); } } public class Child : Parent // Inheritance { public Child() : base("From Derived") //Inherits and calls the base class constructor. { Console.WriteLine("Child Constructor."); } public void print() { base.print(); Console.WriteLine("I'm a Child Class."); } public static void Main() //Static main method, init of application { Child child = new Child(); child.print(); ((Parent)child).print(); } } }
The new class—the derived class—then gains all the non-private data and behavior of the base class in addition to any other data or behaviors it defines for itself. The new class then has two effective types: the type of the new class and the type of the class it inherits.
Class is a structure that describes the state (property) and behavior (methods) of the object. It is a template or blueprint to create objects of the class. Class represents the noun and it can be used as type in programming language. E.g Car, Person etc
What is mean by Objects?
Object is an executable copy of a class. State and behavior of the objects are defined by class definition. We can create multiple objects for single class. It is also called as instance of the class. When an object is created from the class, memory will be allocated in RAM. e.g Car- Maruthi, Alto, Zen etc. Person- Ram, Sam, John etc
What is mean by Struture?
Structure is a light-weight class used to create user-defined types containing only public fields. Structure can't have implementation inheritance, but it can have interface inheritance. We cannot modify the default constructors as like a class. Structure is a value type holds their value in memory when they are declared.
What is difference between Class and Object?
Classes are the template or blueprint its state of how objects should be and behave, where as Object is an actual real term object. E.g CAR define state like it should have four wheel and body structure with moving, accelerating and break functionality. Maruthi, Alto or Zen is the real object which has different kind of state from one another.
What is difference between Class and Structure?
Class is Reference type(Reference types hold a reference to an object in memory) - Structure is a Value type(Value types hold their value in memory when they are declared)
User can modify default constructor and destructor of class- structure can't modify default constructor
Class supports inheritance - Structure will not support inheritance
Classes must be instantiated using the new operator - Structure can be instantiated without using the new operator
Which case we have to use Class and Structure?
Structure can be used for things that we no need for identity. Class can be used when we need the identity for an object.
What is the advantage of Structure over Class?
Since Stucture is a value type and if we use at the proper location, it will improve the performance.
What are advantages of using private constructor, method, property?
Due to security reason, methods and properties are not exposed outside the class using Private access modifier. For implementing Singleton pattern we go for Private Constructor, so we will not able to create instance. Separate method is used to create and return the instance.
What is mean by Partial class?
It is new features in .Net 2.0; partial classes mean that class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. The compiler intelligently combines the definitions together into a single class at compile-time.
Private - The type or member can only be accessed by code in the same class or struct.
Protected - The type or member can only be accessed by code in the same class or struct, or in a derived class.
Internal - The type or member can be accessed by any code in the same assembly, but not from another assembly.
Procted Internal - The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.
Public -The type or member can be accessed by any other code in the same assembly or another assembly that references it.
Note: In VB.Net 'Internal' is called as 'Friend'
What is mean by Partial method?
Partial methods are methods defined in a partial class that are (optionally) divided across two files. With partial methods one file contains the method signature - the method name, its return type, and its input parameters - while the body is (optionally) defined in a separate file. If the partial method's body is not defined then the compiler automatically removes the partial method signature and all calls to the method at compile-time.
Partial methods are mainly useful in auto-generated code situations. A code generating tool might know that there are certain extension points that some users are going to be interested in customizing. For example, the objects created in LINQ to SQL have partial methods like OnLoaded, OnCreated, OnPropertyNameChanging, and OnPropertyNameChanged.
The auto-generated code calls the OnCreated partial method from its constructor. If you want to run custom code when one of these objects is created you can create a partial class and define the body for the OnCreated partial method.
Why do we go for Partial class?
Improve the readability of extremely large classes by partitioning related methods into separate files.
Partial classes enable the code generator to generate code in one file while the developer who may need to extend the auto-generated logic can do so in a separate file, which eliminates the worry that the code generator might overwrite a developer's customizations.
Where we use Partial method and class?
Partial classes and partial methods are most commonly used in auto-generated code. It provides a simple and safe way to add new functionality or extend existing functionality of auto-generated code.
What are restrictions for Partial method?
Partial definitions must preceded with the key word "Partial"
Method signature should be same in both partial class file
We cannot have partial implementation in one file and another implementation in other file. We can have declaration in one file and implementation in another file.
What is mean by Static class?
Static class is used to create attributes and methods that can be accessed without creating the instance of the class. Static classes are loaded automatically by the .NET Framework when application or assembly is loaded. 'Static' key word is used to mention the static class. e.g MyStaticClass.PI
Static method can be accessed without creating the instance of the class. 'Static' key word is used to mention the static method. Static methods can be created inside the normal class or static class. If we create the static method inside the normal class, static method will not be able to access by creating instance of the class. e.g Math.Add()
Can we override static method?
No, compiler will not allow overriding the static method.
What are uses of static class and method?
Compiler will not allow creating the instance of the class
Static class also makes the implementation simpler and faster
Cannot inherit a static class since it is sealed
What is static constructor?
A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced.
Example:
publicclassMyStaticClass{staticintcount;staticMyStaticClass(){count=0;Console.WriteLine("Static class is initialized");}publicstaticvoidMyMethod(stringname){Console.WriteLine("Static class is initialized "+name);}}MyStaticClass.MyMethod("John");
Output:
Static class is initialized
Hello John
What are shared (VB.NET)/Static(C#) variables?
Static members are not associated with a particular instance of any class, which can be invoked directly from the class level, rather than from its instance
Example
publicstaticdoublePI=3.1457;
What is Nested Classes?
Classes with in classes are called as Nested class.
MyClassLevel_1 L1 = new MyClassLevel_1();
MyClassLevel_1.MyClassLevel_2 L2 = new MyClassLevel_1.MyClassLevel_2();
MyClassLevel_1.MyClassLevel_2.MyClassLevel_3 L3 = new
MyClassLevel_1.MyClassLevel_2.MyClassLevel_3();
L1.Display();
L2.Display();
L3.Display();
Output
Level_1
Level_2
Level_3
What are difference between Singleton and Static class ?
Singleton can extend classes and implement interfaces, while a static class cannot implement the interface.
Singleton can be initialized lazily or asynchronously while a static class is generally initialized when it is first loaded.
Singleton class can be extended and it's methods can be overridden.
Why Main () method is static?
To ensure there is only one entry point to the application.
What is mean by inheritance?
Inheritance is one of the concepts of object-oriented programming, where a new class is created from an existing class. Inheritance class is often referred to as subclasses, comes from the fact that the subclass (the newly created class) contains the attributes and methods of the parent class. This can be used to create a highly specialized hierarchical class structure.
No, multiple inheritances are not supported in .Net. Because consider the provided example. Here there are two Parent class Paretn1 and Parent2. This is inherited by Child class, In GetData method, child call the parent class method PrintData().
In this case which method will be executed? It is very difficult for CLR to identify which method to call. It shows that we multiple inheritance create ambiguity to oops concept. In order to avoid this ambiguity we are going for multiple interface implementations.
publicclassParent1{publicstringPrintData(){return"This is parent1";}}publicclassParent2{publicstringPrintData(){return"This is parent2";}}publicclassChild1:Parent1,Parent2{publicstringGetData(){returnthis.PrintData();}}
What is mean by Shadowing?
When the method is defined in base class are not overrideable and we need to provide different implementation for the same in derived class.
In this kind of scenario we can use hide the base class implementation and provide new implementation using Shadows (VB.Net)/new(C#) keyword.
Example:
PublicClass ParentClass
Public Sub Display()Console.WriteLine("Parent class")
End Sub
End Class
Public Class ChildClass
Inherits ParentClass
Public Shadows Sub Display()
Console.WriteLine("Child class")
End Sub
End Class
Dim p As New ParentClass
Dim c As New ChildClass
Dim pc As ParentClass = New ChildClass
p.Display()
c.Display()
pc.Display()Output:Parentclass
Child class
Parent class
How a base class method is hidden?
Using new keyword in the derived class, base class method can be hidden or suppressed. New implementation can be added to the derived class.
What does the keyword virtual mean in the method definition?
The method can be over-ridden.
How method overriding different from overloading?
If we are overriding the method, derived class method behavior is changed from the base class. In Overloading, method with same name by different signature is used.
Example:
publicclassParentClass{publicvirtualvoidDisplay(){Console.WriteLine("ParentClass");}}publicclassChildClass:ParentClass{//Example for method overridepublicoverridevoidDisplay(){Console.WriteLine("ChildClass");}//Example for method overloadpublicvoidDisplay(stringname){Console.WriteLine(name);}//Example for method overloadpublicvoidDisplay(stringname,stringcountry){Console.WriteLine("Name:"+name+"Country: "+country);}}//MainParentClassp=newParentClass();ChildClassc=newChildClass();ParentClasspc=newChildClass();p.Display();c.Display();pc.Display();
OutPut:
ParentClass
ChildClass
ChildClass
Can you declare the override method static while the original method is non-static?
No
What is mean by Sealed Class?
Class which cannot be inherited is called as sealed class. If we need to prevent a class from being inherited, use “Sealed� keyword. But sealed class can inherited from other classes.
Example:
publicclassMyBaseClass{publicvoidDisplay(){Console.WriteLine("Base class");}}//Compile Success: This class cannot be inheritedpublicsealedclassMySealedClass:MyBaseClass{publicvoidDisplay(){base.Display();Console.WriteLine("Sealed class");}}//Compilation Error: cannot derive from sealed type MySealedClasspublicclassMyChildClass:MySealedClass{}
Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed.
Will sealed class allows inheritance, if not why?
Sealed means it is not inheritable
What are the advantages of Private constructor?
Private constructor will prevent the user from creating the instance of the class which contains only static members.
Private constructor are used for implementing the singleton pattern
While using inheritance, derived class construct will call base class constructor?
Yes, base class constructor will be called before child class constructor
Overloaded constructor will call default constructor internally?
No, overload constructor will not call default constructor
What is difference between Overrides and Overridable?
Overridable (VB.Net)/ virtual (C#) is used in parent class to indicate that a method can be overridden. Overrides(VB.Net)/ override(C#) is used in the child class to indicate that you are overriding a method.
What is Method overloading?
Method overloading occurs when a class contains two methods with the same name, but different signatures.
What is operator overloading?
Operator overloading is used to provide a custom functionality to existing operators. For Example +,-,* and / operators are used for mathematical functionality. But we can overload these operators to perform custom operation on classes or structure.
Example:
To concatenate the two strings we have to use Concat method
Abstraction is the process of showing necessary information and hiding unwanted information. Let us consider the "CalculateSalary" in your Employee class, which takes EmployeeId as parameter and returns the salary of the employee for the current month as an integer value. Now if someone wants to use that method. He does not need to care about how Employee object calculates the salary? An only thing he needs to be concern is name of the method, its input parameters and format of resulting member
What is mean by abstraction class?
Abstract classes contain one or more abstract methods that do not have implementation. An abstract class is a parent class that allows inheritance but can never be instantiated. Abstract classes allow specialization of inherited classes.
What id mean by Interface?
Interface defines the set of properties, signature of the methods and events. It does not include any implementation. Class which implements the interface can provide the behavior to the implemented method. For example two class MyEnglishClassand MyFreanchClass implementing same interface and provide two different set of behavior in their implementation.
What is difference between Abstract class and Interface?
In Interface all the method must be abstract; in abstract class we can have both abstract and concrete methods.
Access modifiers cannot be specified in interface because it should always be public; in Abstract class, we can specify the access modifier.
In which Scenario you will go for Abstract or Interface Class?
Abstract classes are useful when creating components because they allow you specify an invariant level of functionality in some methods, but leave the implementation of other methods until a specific implementation of that class is needed. They also version well, because if additional functionality is needed in derived classes, it can be added to the base class without breaking code.
Interfaces are often used to describe the peripheral abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects.
What is mean by polymorphism?
Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.
What are different types of polymorphism?
There are two types of polymorphism
Static polymorphism - defining the method with same name and different signature is called as static polymorphism.
In the below example there are three different Add() functionality this Add() will be executed based on the parameter passed.
Dynamic polymorphism Dynamic polymorphism can be implemented using virtual and override keyword. By using polymorphism, each derived class can have its own behavior, Even though classes are derived or inherited from the same parent class
Example:
In the below example ClassB is inherited from ClassA. ClassB can have its own behavior by overriding the parent class method. Parent class method should be represented with virtual keyword to override the same method in derived class.
Encapsulation is the procedure of covering up of data and functions into a single unit and protects the data from the outside world. Example “Class� only public functions and properties are exposed; functions implementation and private variables are hidden from outside world.
What is difference between data encapsulation and abstraction?
Abstraction refers to the act of representing essential features without including the background details or explanations. Storing data and functions in a single unit is called as encapsulation.
What is mean by Delegate?
Delegate is a type that holds a reference to a method or a function. . Once a delegate is assigned a method, it behaves exactly like that method. We can call the method using delegate instead of directly calling the method. Using delegate, we can also pass the parameter and get return value. Any method with matched the signature of the delegate can be assigned. Simply we can say .NET implements the concept of function pointers using delegate.
Example:
There are three step to following for using Delegate
Declaration
Instantiation
Invocation
In the below example we have declared the new delegate MyDelegate, which accept string as parameter and return value as string. Two methods SayHello and SayBye function will be called using delegate.
//Declaring the delegatedelegatestringMyDelegate(stringname);//function called by delegate dynamicallyprivatestaticstringSayHello(stringname){return"Hello "+name;}privatestaticstringSayBye(stringname){return"Bye "+name;}
After declaration of delegate, we have initialized with SayHello function. Now this delegate will hold reference to specified function. Function will be called using Invoke () method of delegate. In this example we have called two methods (SayHello and SayBye) with same signature(parameter type and return type).
staticvoidMain(string[]args){//Initialllizing delegate with function nameMyDelegatedelg=newMyDelegate(SayHello);//Invoking function using delegateConsole.WriteLine(delg.Invoke("Sam"));delg=newMyDelegate(SayBye);//Invoking diffent function using same delegateConsole.WriteLine(delg.Invoke("Sam"));Console.ReadLine();}
OutPut:
Hello Sam
Bye Sam
What's a multicast delegate?
It's a delegate that stores the address of multiple methods and eventually fires off several methods. Multicast delegate must have a return type of void.
What is an Asynchronous delegate?
When you invoke a delegate asynchronously, no new thread is created. Instead, the CLR automatically assigns a free thread from a small thread pool that it maintains. Typically, this thread pool starts with one thread and increases to a maximum of about 25 free threads on a single-CPU computer. As a result, if you start 50 asynchronous operations, one after the other, the first 25 will complete first. As soon as one ends, the freed thread is used to execute the next asynchronous operation.
What is mean by Events?
Events are nothing but a publisher and subscriber model. Any subscriber who is interested in receiving notification from the publisher can subscribe the events. If source event is fired or publisher raises the event, a notification will be send to all subscribers. One publisher can have multiple subscribers. Internally events will try to make use of delegate for this publisher, subscription model.
Example:
In the below example, we have created new event called SampleEvent and this event will be fired once MyMethod() is called. Anyone who wants to subscribe to this event can create a instance of the MyClassWithEvent and add handler to the event. So when ever event is raised, add handler method will be called.
PublicClassMyClassWithEvent'Created New Event, which will return a message to all subscriberEventSampleEvent(ByValmessageAsString)'Event will be fired once this method is calledPublicSubMyMethod()Console.WriteLine("MyMethod is called")'Raising the event with messageRaiseEventSampleEvent("Event is Raised from MyClassWithEvent")EndSubEndClassModuleModule1SubMain()DimcAsNewMyClassWithEvent'First subscriber of the eventAddHandlerc.SampleEvent,AddressOfEventSubscriber1'Second subscriber of the eventAddHandlerc.SampleEvent,AddressOfEventSubscriber2c.MyMethod()Console.ReadLine()EndSubPrivateSubEventSubscriber1(ByValmessageAsString)Console.WriteLine("Subscriber 1")Console.WriteLine("Message: "+message)EndSubPrivateSubEventSubscriber2(ByValmessageAsString)Console.WriteLine("Subscriber 2")Console.WriteLine("Message: "+message)EndSubEndModule
OutPut:
MyMethod is called
Subscriber 1
Message: Event is Raised from MyClassWithEvent
Subscriber 2
Message: Event is Raised from MyClassWithEvent
Can events have access modifiers?
Yes, Event’s can have access modifier, if we mention it as Protected events can be subscribed only within inherited class, If you mention it as Internal(C#)/Friends(VB.Net) it can be subscribed by all class inside the assembly. If you mention it as Private it can subscribed with in class where it is declared.
Can we have static/shared events?
Yes, we can have static(C#)/shared(VB.Net) event, but only shared method can raise shared events.
Can we have different access modifier for Get/Set of the properties?
Yes, in C# 3.0 and above, we can use different access modifier for Get/Set of the properties, but this is not possible in C#2.0 and lower
What is an indexer?
An indexer is an accessor that enables an object to be treated in the same way as an array. An indexer is considered when a class is better represented as a virtual container of data that can be retrieved or set using indices. Since an indexer is nameless, its signature is specified by the keyword “this� followed by its indexing parameters within square brackets.
Example:
In the below example we have created new index for class of type string. During get and set operation string manipulations are done.
publicclassMyClassForIndexer{privatestringm_Name="This is example for indexer";publicstringthis[intindex]{get{returnm_Name.Substring(index);}set{m_Name=m_Name.Insert(index,value);}}}MyClassForIndexerind=newMyClassForIndexer();Console.WriteLine(ind[0]);ind[7]="Appended String";Console.WriteLine(ind[0]);
Output:
This is example for indexer
This isAppended String example for indexer
What is ENUM?
ENUM means Enumeration; it is used to group related sets of constants. To create a enumeration you use the Enum statement
Example:
Enum Months
January = 1
Feburary = 2
March = 3
April = 4
May = 5
June = 6
July = 7
August = 8
September = 9
October = 10
November = 11
December = 12
End Enum
A process is a collection of threads that share the same virtual memory. A process has at least one thread of execution, and a thread always run in a process context.
What is Thread?
Threads are the basic unit to which an operating system allocates processor time, and more than one thread can be executing code inside that process.
What is Multi-threading?
Multi threading is the collection of thread executed with in the same program to generate the output.
What is Multi-tasking?
It's a feature of modern operating systems with which we can run multiple programs at same time example Word, Excel etc.
What is the namespace used for threading?
System.Threading
Note: - .NET program always has at least two threads running one is the main program and second is the garbage collector.
What is mean by AppDomain?
Operating system process are subdivides into lightweight managed sub processes called application domains. One or more managed threads (represented by System.Threading.Thread) can run in one or any number of application domains within the same managed process.
Although each application domain is started with a single thread, code in that application domain can create additional application domains and additional threads.
Can you explain in brief how can we implement threading?
This sample explains about the implementation of the threading. Let start this example by creating a class with two methods called "Thread1()", "Thread2()"
classTestClass{publicvoidThread1(){intindex=0;for(index=0;index<100;index++){Console.WriteLine("This is from first thread: {0}",index.ToString());}}publicvoidThread2(){intindex=0;for(index=0;index<100;index++){Console.WriteLine("This is from second thread: {0}",index.ToString());}}}
Create a new console application; in the main method we will be creating the new instance of the Thread and pass the address of the TestClass method as constructor parameter to the Thread class.
Start the Thread by calling the Thread.Start() method.
The Thread.sleep() method effectively "pauses" the current thread execution for a given period of time. This method takes an integer value as parameter that determines how long the thread needs to be paused.
Example:
System.Threading.Thread.Sleep(4000);
How can we make a thread sleep for infinite period?
You can also place a thread into the sleep state for an indeterminate amount of time by calling Thread.Sleep(System.Threading.Timeout.Infinite).
To interrupt this sleep you can call the Thread.Interrupt method.
What is mean by Thread.Suspend and Resume?
Thread.Suspend() - this method is used to suspend the thread execution. If the method is already suspended, it does not have any effect.
Thread.Resume() - Suspended thread can be resumed using this method call.
What is difference between Thread.Sleep and Thread.Suspend()?
Thread.Sleep() method will immediately place the thread under wait state, where as
Thread.Suspend() method will not go into wait state until .net determines that it is in a safe place to suspend it.
What the way to stop a long running thread?
Thread.Abort() stops the thread execution at that moment itself.
How will we get current thread?
Using System.Threading.Thread.CurrentThread we will be able to get the current thread instance.
How we can make the thread run in background?
By setting ThreadName.IsBackground = true will run the Thread in background process.
What are Daemon threads and how can a thread is created as Daemon?
Daemon thread's are threads run in background and stop automatically when nothing is running program. Example of a Daemon thread is "Garbage collector".
Garbage collector runs until some .NET code is running or else it's idle. Thread can be made as Daemon by Thread.Isbackground=true
How to debug the thread?
Threading application can be debugged using Debug->Windows->Threads or "Ctrl+Alt+H"
How we can use the same variable by multiple thread or Thread safe?
In certain scenario, multiple threads must need to access the same variable at the same time; this will leads to some other problem. This can be avoided by using SynchLock. So until first thread released its variable, other thread will not be able to access the variable.
Example:
SyncLock(X)
'some operation with "X"
End SyncLock
What are different states of a thread?
Thread status can be known by using ThreadName.ThreadState property. ThreadState enumeration has all the values to detect a state of thread. Some sample states are Aborted, Running, Suspended, etc
Yes, we can use events with thread; this is one of the techniques to synchronize one thread with other.
What is Event Wait Handle in threading?
Event Wait Handle allows threads to communicate with each other by signaling and by waiting for signals. Event wait handles are wait handles that can be signaled in order to release one or more waiting threads.
What is difference between Monitor object and EventWaitHandle?
Both EventWaitHandles and Monitors are used to synchronize activities But Named event wait handles can be used to synchronize activities across application domains and processes, whereas monitors are local to an application domain.
What is mean by ManualResetEvent and AutoResetEvent?
Threads that call one of the wait methods of a synchronization event must wait until another thread signals the event by calling the Set method. There are two synchronization event classes.
Threads set the status of ManualResetEvent instances to signaled using the Set method.
Threads set the status of ManualResetEvent instances to no signaled using the Reset method or when control returns to a waiting WaitOne call. Instances of the
AutoResetEvent class can also be set to signaled using Set, but they automatically return to nonsignaled as soon as a waiting thread is notified that the event became signaled.
What is mean by Deadlock in Threading?
Dead lock issue will be raised when multi thread try to access the same variable. Example when both the threads try to hold and monitor the variable at same time. Each thread monitor and wait for another thread to release the variable.
Since no one is hold the variable and both the threads are waiting for the other thread to release each other, at last application hangs. This is called as Deadlock.
This C# code snippet declares an event with EventHandler using the default implementation for removing events and subscribing to events. We implement the IDisposable interface simply to have a reasonable excuse to throw an event.
using System;
public class MyClass : IDisposable
{
public event EventHandler Disposing;
public void Dispose()
{
// release any resources here
if (Disposing != null)
{
// someone is subscribed, throw event
Disposing (this, new EventArgs());
}
}
public static void Main( )
{
using (MyClass myClass = new MyClass ())
{
// subscribe to event with anonymous delegate
myClass.Disposing += delegate
{ Console.WriteLine ("Disposing!"); };
}
}
}
This sample demonstrates versioning in C# through the use of the override and new keywords. Versioning maintains compatibility between base and derived classes as they evolve.
// versioning.cs public class MyBase { public virtual string Meth1() { return "MyBase-Meth1"; } public virtual string Meth2() { return "MyBase-Meth2"; } public virtual string Meth3() { return "MyBase-Meth3"; } }
class MyDerived : MyBase { // Overrides the virtual method Meth1 using the override keyword: public override string Meth1() { return "MyDerived-Meth1"; } // Explicitly hide the virtual method Meth2 using the new // keyword: public new string Meth2() { return "MyDerived-Meth2"; } // Because no keyword is specified in the following declaration // a warning will be issued to alert the programmer that // the method hides the inherited member MyBase.Meth3(): public string Meth3() { return "MyDerived-Meth3"; }
public static void Main() { MyDerived mD = new MyDerived(); MyBase mB = (MyBase) mD;