zoukankan      html  css  js  c++  java
  • 第二十章:封装与继承

    代码 :

    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
        {
    
        }
    }
  • 相关阅读:
    正则表达式(转)
    Collections中的shuffle()方法
    Fermat定理
    哈希算法(转)
    Hungarian method (匈牙利算法)----解决指派问题(转)
    蒙塔卡洛模拟
    线程的礼让
    线程间的沟通
    安装rlwrap
    yum切到光盘源
  • 原文地址:https://www.cnblogs.com/wangqiangya/p/13062590.html
Copyright © 2011-2022 走看看