第二十章:封装与继承

代码 :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 封装
{
    class Program
    {
        static void Main(string[] args)
        {
            Teacher st = new Teacher();
            //st.str
            int a= st.Sum(1, 2);

            Sudent s = new Sudent();
            int b= s.Sum(2, 3);
            Console.WriteLine(a);
            Console.ReadKey();
        }
    }
    public class Teacher
    {
        /// <summary>
        /// 封装计算和的方法
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public int Sum(int a, int b)
        {

            int result = a + b;
            return result;
        }
        //{ }  int a=1;
        //方法有两种形式,一种是有返回值,一种是没返回值 void
        // string 字符串  int 数字  double  小数 bool 真假值  list<T>  

        //void  表示不返回值
        public string str()
        {
            
            Console.WriteLine("234wer");
            return "";
        }
    }
    /// <summary>
    /// 继承   :对象
    /// </summary>
    public class Sudent : Teacher
    {

    }
}
原文地址:https://www.cnblogs.com/wangqiangya/p/13062590.html