Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Differences between method overloading and method overriding

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 7 Anzeige

Weitere Verwandte Inhalte

Anzeige

Ähnlich wie Differences between method overloading and method overriding (20)

Aktuellste (20)

Anzeige

Differences between method overloading and method overriding

  1. 1. Differences between method overloading and method overriding Answer: Method Overloading and Method Overriding are both the techniques used to implement FUNCTIONAL POLYMORPHISM They enhance the methods functionality using their respective features. overloading: 1) It involves having another method with the same name in a class or its derived class. 2)can be implemented with or without inheritance. 3)It is implemented by: a)changing the number of parameters in different methods with same name. b)changing the parameter data types (if the number of parameters are same) c)changing parameter order. 4)applicable to static as well as non static methods: 5)no keywords needed before the method names in C#. 6)also called as COMPILE TIME Polymorphism. example: int add(int a, int b) { return a+b; } int add(int a) { return a*5; } Overriding: 1) It involves having another method with the same name in a base class and derived class.
  2. 2. 2)always needs inheritance. 3)It is implemented by having two methods with same name, same signature, but different implementations (coding)in a base class and derived class 4)applicable to nonstatic, nonprivate methods only.access modifiers of the methods are not changed in the base and derived classes. 5)virtual and override keywords are needed before the method names in base and derived classes. For overriding in firther classes, override keyword will be used, 6)RUN TIME Polymorphism example: class A { public virtual void demo() { } } class B:A { public override void demo() { } static void Main() { B obj=new B(); obj.demo(); } } What is CLS? Answer: CLS: Common Language Specification:
  3. 3. It is a set of the programming rules which every .NET language must follow. CLS is used so that the code written in one language is interoperable with the code written in another language. The different .NET languages code is compiled into MSIL Code. CLS defines the infrastructure for the MSIL Code. The CLR processes the MSIL code and help in its execution. This ensures the language interoperability. EXAMPLES OF CLS: 1)Common set of data types for all the languages( CTS) Int32 datatype is implemented as int in C# and as integer in VB.NET 2)Interfaces cannot have static methods.It applies to all the .NET languages. The Types which follow the CLS rules are also called as CLS Compliant types. CLS compliant languages: VB.NET,C#, VC++ Use of CLS: A class written in VB.NET can be used in C# and vice-versa. For the complete list of CLS features, please visit this link. http://msdn.microsoft.com/en-us/library/12a7a7h3(VS.71).aspx What is .NET Framework? Answer: .NET (.Network Enabled Technologies) is a collection of development tools developed by the Microsoft Corporation that enables the developers to develop and execute a large variety of applications example: Console,Windows,Web,WPF,WCF, Web Services, Window Services, Mobile Applications.
  4. 4. .NET Framework consists of: 1)CLR: (Common Language Runtime): 2)FCL: (Framework Class Llivraries) 3)Languages, Language Compilers CLR is the set of components(also called as the execution engine) and provides us with many runtime services. example: 1)Managing code execution. 2)Menory management and Garbage Collection. 3)Exception handling management 4)Security and Code Verification 5)MultiThreading support 6)Cross Language interoperability using CTS and CLS. FCL provides us with the predefined class libraries which have over thousands of classes that can be used in development and execution. example: System.Data.dl System.Windows.Forms.dll System.dll mscorlib.dll Languages :example: VB.NET, C#,VC++ Each language ahs its own set of compilers ex: vbc for vb.net, csc for csharp. Coompilers are used to compile the code and generate the executable files.(Assemblies) What is difference between out and ref in c#? Answer: This is a great .NET Interview question and also very very confusing question. By default parameters are always passed by value to methods and functions.If you want to pass data byref then you can use either out or ref keyword. There are two big difference between these keywords one is the way data is passed between the caller code and method and second who is responsible for initialization.
  5. 5. Way the data is passed(directional or bi-directional) ================================================== When you use OUT data is passed only one way i.e from the method to the caller code. When you use REF , Data can be passed from the called to the method and also vice versa. Who initializes data ============================================== In OUT the variables value has to be intialized in the method. In REF the value is initialized outside the method by the caller. The most important thing the interviewer will like to hear from you When to use when ====================================================== OUT will be used when you want data to be passed only from the method to the caller. REF will be used when you want data to be passed from the called to the method and also vice versa. My 100 .NET Interview questions http://www.questpond.com What is the difference between .NET 1.1,2.0,3.0,3.5 and 4.0 ? Answer: The list of differences are huge. In interviews you normally need to short and sweet. So we will list down top 5 differences from each section. So lets first start with the difference between 1.0 and 2.0. Support for 64 bit application. Generics SQL cache dependency Master pages Membership and roles Now the next difference .NET 2.0 and 3.0 ========================================= WCF WPF WWF WCS ( card space) 3.0 and 3.5
  6. 6. ========================================== LINQ Ajax inbuilt ADO Entity framework ADO data services Multi targeting Finally 3.5 and 4.0 =========================================== MEF Parallel computing DLR dynamic Code contract language runtime Lazy initialization Differences between Window and Web Forms Answer: Window Forms: 1)They do not need a web browser or web server to execute. 2)They execute through their respective exe files 3)They run on the same machine they are displayed on. 4)Their single instance exists until we close them or dispose them through coding 5)Used for developing games, inventory management, system utiltites etc. 6)They run under Code Access Security. Web Forms: 1)They need a web browser as well as a web server(on the server machine only). 2)They execute through the dll of the web application which is then processed by IIS and the .net
  7. 7. framework. 3)They run on a remote server and are displayed remotely on the clients. 4)Every time they are submitted, their new instance is created. 5)Used in web site development. 6)They use role based security

×