Additional method concept please add a class to an application that implements i
ID: 3606492 • Letter: A
Question
Additional method concept please add a class to an application that implements in encapsulation and all types of members including constructors and methods . Please brainstorm and come up with 10 examples of method overloading please explain each Matt did please note that these should be ideas, not code examples. You will be taken to task with writing a method that adds an unknown number of INT(int) values and return of the results as a double. Use parameters arrays to receive the value to be added nli d2/le/content/47089/viewContent/2215956/View My Home CI2040-C# Program Jason Cla LP7 Assignments Learning Plan 7 Assignments LP7 Assignment: Additional Method Concepts nt will assess Competency 7. Add a class to an application that implements encapsulation and all types of This assignme members including constructors and methods. Directions: For this week's assignment, you will brainstorm and come up ten examples of method overloading. You will draft a paper in which you explain each of these methods. Please note that these should be ideas, not coded examples. You will also be tasked with writing a method that adds an unknown number of int values and returns the result as a double. Use parameter arrays to receive the values to be added. Create a MS Word file that contains your name, chapter, exercise number, and code. Submit this assignment to your instructor via the dropbox "LP7 Assignment: Additional Method Concepts. This assignment is worth 60 points and will be graded according to the scoring guide below Scoring Guide (60 Points) 30-27 work meets or exceeds criterion at a high level of competence. of criterion with minor s/m sconceptions. Crit orExplanation / Answer
In this particular solution we are required to give 10 examples of methode overloading .The following are the different types -
1.Type of parameter inoverloaded functions are different as such can be overloaded
During functions call the appropriate parameter type is noted and called accordingly
using System;
class Example
{
static void check(int x)
{
Console.WriteLine(x);
}
static void check(string x)
{
Console.WriteLine(x);
}
static void Main()
{
check("text");
}
}
2.Using Multiple parameters in the overloaded functions.In this particular case the number of
parameters is checked and function is called accordingly
class Example
{
static void check(int x,int y)
{
Console.WriteLine(x);
}
static void check(int x)
{
Console.WriteLine(x);
}
static void Main()
{
check(40);
}
}
3.Return type of the function are different - In this particular type
only the return types of the overloaded functions are different
class Example
{
static int check(int x)
{
Console.WriteLine(x);
return 0;
}
static void check(int x)
{
Console.WriteLine(x);
}
static void Main()
{
check(40);
}
}
4.Using optional parameters - In this particular case one function parameter may be
optional while in the other it might not have any such optional parameter
class Example
{
static int check(int x=4,int y=30)
{
Console.WriteLine(x);
return 0;
}
static void check(int x)
{
Console.WriteLine(x);
}
static void Main()
{
check(40);
}
}
5.Using similar primitive datatypes in th parameters- using similar datatypes
in the parameter list like int,floar,double in the parameter list will confuse the
compiler.But it will surely be overloaded.
class Example
{
static void check(int x)
{
Console.WriteLine(x);
}
static void check(double x)
{
Console.WriteLine(x);
}
static void Main()
{
check(40.12);
}
}
6.Using Named parameters - named parameters is another mode of overloading
using System;
class Example
{
static void check(int x)
{
Console.WriteLine(x);
}
static void check(double y)
{
Console.WriteLine(y);
}
static void Main()
{
check(y: 10); //named parameter usage
}
}
7.Using inheritances - Overloading an function after inheriting is another mode of overloading
in the subclasses.
using System;
class A
{
public void check(int x)
{
Console.WriteLine(x);
}
}
class B : A
{
public void check(double y)
{
Console.WriteLine(y);
}
}
class Test
{
static void Main()
{
B c = new B();
c.check(100);
}
}
8.Using Interfaces - Thought an interface is actually overriding,it can also be used for overloading a
function in the followinf process.
using System;
interface intf
{
void check(int x);
}
class A : intf
{
public void check(int x)
{
Console.WriteLine(x);
}
}
class B : A
{
public void check(double y)
{
Console.WriteLine(y);
}
}
class Test
{
static void Main()
{
B c = new B();
c.check(100);
}
9.Overloading a function having different access specifiers - The particular type of overriding where the functions can be identified only after the different access specifiers.
This type are generally used in inheritances.
using System;
class A
{
public void check(int x)
{
Console.WriteLine(x);
}
}
class B : A
{
protected void check(double y)
{
Console.WriteLine(y);
}
}
class Test
{
static void Main()
{
B c = new B();
c.check(100);
}
}
10.Overloading a function during inheritance having different number of parameters
using System;
class A
{
public void check(int x)
{
Console.WriteLine(x);
}
}
class B : A
{
protected void check(double y,int k)
{
Console.WriteLine(y);
}
}
class Test
{
static void Main()
{
B c = new B();
c.check(100);
}
}
11. Overloading a function having different arrangement of their parameters
using System;
class Example
{
static void check(int x,String y)
{
Console.WriteLine(x);
}
static void check(String x,int y)
{
Console.WriteLine(y);
}
static void Main()
{
check("abc",123);
}
}
Thus all the process have been included
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.