C # Calculate the sum of two numbers in Task 4 of week 3

Source: Internet
Author: User

[Csharp]
/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: calculates the sum of two numbers.
* Author: Xue Guangchen
* Completion date: January 1, September 19, 2012
* Version No.: X1.0
* Description of tasks and Solutions
* Input Description: Create an abstract class A, which contains an abstract Method for Calculating the sum of two numbers.
* Create a subclass B, rewrite the summation method in B, and use method overload to calculate integers, double precision, and strings respectively.
* Problem description:
* Program output:
 
* End the comment in the program Header
 
*/
 
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
 
Namespace Calculate
{
Class Program
{
Static void Main (string [] args)
{
B B = new B ();
B. summation ("abcd", "efg ");
B. summation (6, 9 );
B. summation (7.5, 6.3 );


Console. ReadKey ();
}
}

Abstract class
{
Public abstract void summation (int I, int j );
}
Class B:
{
Public override void summation (int I, int j)
{
Console. WriteLine (I + j );
 
}
Public void summation (double I, double j)
{
Console. WriteLine (I + j );
}
Public void summation (string I, string j)
{
Console. WriteLine (I + j );
}
}
 
}
 

Running result:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.