What is method overloading, and when is it useful?

1 Answer

Answer :

Method overloading allows you to create several methods with the same name but different signatures. Overloading is useful when you want to provide the same or similar functionality to different sets of parameters.

Related questions

Description : How is method overriding different from method overloading? 

Last Answer : When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

Description : How is method overriding different from method overloading? 

Last Answer : When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

Description : How’s method overriding different from overloading?

Last Answer : When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

Description : Define what is meant by method overloading?

Last Answer : Method overloading permits multiple methods in the same class to have the same name as long as they have unique signatures. When compiling an invocation of an overloaded method, the compiler uses overload resolution to determine the specific method to invoke.

Description : Describe XCOPY deployment. Under what conditions is it useful? When can it not be used?

Last Answer : XCOPY deployment is a simple method of deployment where the DOS command XCOPY is used to copy the application directory and any subdirectories to the target machine. You can use XCOPY ... an application requires a more complex deployment or references shared assemblies, you cannot use XCOPY.

Description : Describe an abstract class and explain when one might be useful.

Last Answer : An abstract class is a class that cannot be instantiated but must be inherited. It can contain both implemented methods and abstract methods, which must be implemented in an inheriting class. ... common interface for other methods, and leave more detailed implementation up to the inheriting class.

Description : What is a delegate useful for?

Last Answer : The main reason we use delegates is for use in event driven programming. 

Description : Explain how to use the Begin and End methods on a Web Service to make an asynchronous method call.

Last Answer : Every public Web method on a Web Service can be called either synchronously or asynchronously. To make an asynchronous call to a Web method, you call the method named Begin, where is the name of ... returned by Begin. This will allow you to retrieve the actual data returned by the Web method.

Description : What does the Dispose method do with the connection object? 

Last Answer : Deletes it from the memory. To Do: answer better. The current answer is not entirely correct.

Description : What does assert() method do?

Last Answer : In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true. 

Description : What are the different ways a method can be overloaded?

Last Answer : Different parameter data types, different number of parameters, different order of parameters.

Description : Can you declare an override method to be static if the original method is not static? 

Last Answer : No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)

Description : What does the keyword “virtual” declare for a method or property? 

Last Answer : The method or property can be overridden. 

Description : What’s the implicit name of the parameter that gets passed into the set method/property of a class?

Last Answer : Value. The data type of the value parameter is defined by whatever data type the property is declared as.

Description : What happens if you inherit multiple interfaces and they have conflicting method names?

Last Answer : It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay. To Do: Investigate 

Description : Can you allow a class to be inherited, but prevent the method from being over-ridden?

Last Answer : Yes. Just leave the class public and make the method sealed. 

Description : Are value types are slower to pass as method parameters? 

Last Answer : Yes

Description : What is an overloaded method?

Last Answer : An overloaded method has multiple signatures that are different. 

Description : Write code to show how a method can accept a varying number of parameters.

Last Answer : using System; namespace Console1 { class Class1 { static void Main(string[] args) { ParamsMethod(1,"example"); ParamsMethod(1,2,3,4); Console.ReadLine(); } static void ... o in list) { Console.WriteLine(o.ToString()); } } } }

Description : Methods must declare a return type, what is the keyword used when nothing is returned from the method?

Last Answer : void 

Description : What does the Dispose method do with the connection object? 

Last Answer : Deletes it from the memory. To Do: answer better. The current answer is not entirely correct.

Description : What does assert() method do? 

Last Answer : In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true. 

Description : What are the different ways a method can be overloaded?

Last Answer : Different parameter data types, different number of parameters, different order of parameters.

Description : Can you declare an override method to be static if the original method is not static? 

Last Answer : No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)

Description : What does the keyword “virtual” declare for a method or property? 

Last Answer : The method or property can be overridden.

Description : What’s the implicit name of the parameter that gets passed into the set method/property of a class?

Last Answer : Value. The data type of the value parameter is defined by whatever data type the property is declared as.

Description : What happens if you inherit multiple interfaces and they have conflicting method names?

Last Answer : It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.  To Do: Investigate 

Description : Can you allow a class to be inherited, but prevent the method from being over-ridden?

Last Answer : Yes. Just leave the class public and make the method sealed. 

Description : How can you overload a method?

Last Answer : Different parameter data types, different number of parameters, different order of parameters.

Description : Can you allow class to be inherited, but prevent the method from being overridden? 

Last Answer : Yes, just leave the class public and make the method sealed. 

Description : Can you declare the override method static while the original method is nonstatic?

Last Answer : No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override. 

Description : What does the keyword virtual mean in the method definition? 

Last Answer : The method can be over-ridden. 

Description : What’s the implicit name of the parameter that gets passed into the class’ set method?

Last Answer : Value, and it’s datatype depends on whatever variable we’re changing. 

Description : Define what is the Static Method?

Last Answer : It is possible to declare a method as Static provided that they don’t attempt to access any instance data or other instance methods.

Description : Define what is the difference between an abstract method & virtual method?

Last Answer : An Abstract method does not provide an implementation and forces overriding to the deriving class (unless the deriving class also an abstract class), whereas the virtual method has an ... abstract method does not provide implementation & forces the derived class to override the method.

Description : Can we declare a method as sealed?

Last Answer : In C# a method can’t be declared as sealed. However, when we override a method in a derived class, we can declare the overridden method as sealed. By declaring it as sealed, we can avoid further overriding of this method.

Description : Which method will you call to start a thread?

Last Answer : Start

Description : How can we suppress a finalize method?

Last Answer : GC.SuppressFinalize()

Description : Define what are the different ways a method can be overloaded?

Last Answer : Different parameter data types, different number of parameters, different order of parameters.

Description : Can “this” be used within a static method?

Last Answer : No ‘This’ cannot be used in a static method. As only static variables/methods can be used in a static method.

Description : Can we override the private virtual method in C#?

Last Answer : No. We can’t override private virtual methods as it is not accessible outside the class.

Description : Can we use “this” inside a static method in C#?

Last Answer : No. We can’t use “this” in a static method.

Description : What is a Method Overloading?

Last Answer : Method with same name but with different arguments is called method overloading

Description : Differentiate between method overloading and method overriding.

Last Answer : Sr. No. Method overloading Method overriding 1 Overloading occurs when two or more methods in one class have the same method name but different parameters. Overriding means having two ... 4 overloading is a compiletime concept. Overriding is a run-time concept

Description : What si the difference between interface and abstractclass Select Answer:  1. interface contain only methods  2. we can't declare a variable for interface  3. interface contain only events  4. None  5. All

Last Answer : Ans : 2 The only Difference between Interface and Abstract class is we can declare a variable in abstract class but we can't declare in variable interface

Description : What is the lifespan for items stored in ViewState? Select Answer:  1. Item stored in ViewState exist for the life of the current page  2. Item stored in ViewState exist for the life ... of the current Applicaiton  4. Item stored in ViewState exist for the life of the current configuration

Last Answer : 1. Item stored in ViewState exist for the life of the current page AS any web application works on request and response basis ,so on every post backs, The data in control gets lost. To retain page ... control with data. The life cycle of the view state exist for life of current running page only. 

Description : Which one of the following tools is used to view the metadata information contained in a .NET assembly? Select Answer:  1. al.exe  2. ilasm.exe  3. vbx.exe  4. csc.exe  5. ildasm.exe

Last Answer :  5. ildasm.exe

Description : How would you ensure that all relevant registry entries were removed in the event that installation of your application failed?

Last Answer : You can ensure that registry entries are removed, as well as perform any other “clean-up” tasks, by creating an Installer class and writing the appropriate code in the Rollback event handler. Then create a new Custom Action and set the InstallerClass, and EntryPoint properties to appropriate values.

Description : Describe a general strategy for creating a setup project that terminates installation if a specific file is not already installed on the target machine.

Last Answer : First, create a file search to search the file system for the specific file. Then create a launch condition to evaluate the results of the search. You can connect the launch condition to ... in the search's Property property in the expression specified by the launch condition's Condition property. 

Description : What is the purpose of a bootstrapper application? When do you not need to create one?

Last Answer : A bootstrapper application automatically detects if Windows Installer is installed on the target machine. If Windows Installer is not present, it installs Windows Installer before proceeding with the rest ... Installer 1.5 already installed) or have had Microsoft Installer 1.5 installed previously.