Write a program to create ‘testMaths2’ class with x, y members. Accept the X, Y values from User, using Parameterized Constructor pass the values to x, y members and assign the values. Calculate the Addition, Subtraction values for x, y members. Show the Object content on a Console application.
class TestMath2
{
int x, y;
public TestMath2(int x, int y)
{
this.x = x;
this.y = y;
}
public void Add()
{
Console.WriteLine("Addition Result:" + (x + y));
}
public void Sub()
{
Console.WriteLine("Difference Result:" + (x - y));
}
}
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Enter First number");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second number");
b = int.Parse(Console.ReadLine());
TestMath2 obj = new TestMath2(a, b);
obj.Add();
obj.Sub();
Console.ReadLine();
}
output:
No comments:
Post a Comment