当前位置: 首页 > news >正文

广州网站建设公司广州企业网站建设公司公司网站建设网站建设与网站设计

广州网站建设公司广州企业网站建设公司公司网站建设,网站建设与网站设计,服装网站设计方案,建设银行网站特点分析本文介绍不同类型的方法#xff0c;在代码中的执行顺序问题#xff1a; 构造方法普通方法#xff08;暂用common代替#xff09;、虚方法#xff08;Virtual修饰#xff09;、New方法#xff08;new修饰#xff09;三个优先级相同overide方法#xff08;会替换virtual… 本文介绍不同类型的方法在代码中的执行顺序问题 构造方法普通方法暂用common代替、虚方法Virtual修饰、New方法new修饰三个优先级相同overide方法会替换virtual方法此时virtual方法被隐藏无法再调用到 1. 构造函数方法(constructor)优先级最高new/common/virtual/这三个修饰的方法优先级相同 当父类、子类中的方法都是new/common/virtual/这三类的时候可以理解为实例化对象的类型等号左边的类型是什么就优先调用哪个类中的方法。父类初始化之后无法生成子类的实例化对象。因整个过程没有初始化子类的过程不会生成子类对象。 using ConsoleDeomAlien; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleDeomAlien {public class Product{public Product(){Console.WriteLine(old Constructor-------Product);}public void Intro(){Console.WriteLine(old method--------Intro\n);}}public class NewProduct : Product{public NewProduct(){Console.WriteLine(new Constructor-------NewProduct);}// 这里使用new修饰或不用new都可以。都代表对父类进行重写。// 如果父类注定要被子类重写的父类中可以写个空方法后续子类直接重写即可。public new void Intro() {Console.WriteLine(new method--------Intro\n);}}public class MainMethod{public static void Main(){Product p new Product(); // 初始化和实例对象是相同的此时该class中的方法仅仅是被重写未被覆盖改方法还起作用。// 最终有限调用自己class中的方法p.Intro();NewProduct np new NewProduct();// 子类优先调用该类下面的方法。np.Intro();Product p_np new NewProduct();// 初始化对象是用的子类但是对象是父类类型最终会优先调用父类的方法。p_np.Intro();// !!!不符合逻辑的实例化过程因为父类初始化之后没有调用子类的构造函数无法生成子类的实例对象!!!// NewProduct np_p new Product ();Console.ReadKey();}} } old Constructor-------Product old method--------Introold Constructor-------Product new Constructor-------NewProduct new method--------Introold Constructor-------Product new Constructor-------NewProduct old method--------Intro 2. virtual / override 修饰的父、子类中的方法最终virtual方法会被覆盖且virtual被隐藏无法起作用 using ConsoleDeomAlien; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleDeomAlien {public class Product{public virtual void Intro(){Console.WriteLine(old method--------Intro\n);}}public class NewProduct : Product{public override void Intro(){Console.WriteLine(new method--------Intro\n);}}public class MainMethod{public static void Main(){Product p new Product();p.Intro();NewProduct np new NewProduct();np.Intro();// 虽然实例对象是父类但是调用不到父类的方法了因为被隐藏了。Product p_np new NewProduct(); p_np.Intro();Console.ReadKey();}} } old method--------Intronew method--------Intronew method--------Intro 构造方法的优先级最高父类中的void方法会被子类中的普通common方法或virtual 方法覆盖。virtual common 同等级。当子类中没override的时候new会覆盖virtual / common当override存在时virtual会被替代掉virtual可以父类无法调用到virtual中的方法
http://www.yutouwan.com/news/495477/

相关文章:

  • 网站查询 工信部wordpress 多栏目
  • 开家网站设计公司免费咨询刑事辩护在线律师
  • 韩国网站设计风格万网域名安装wordpress
  • 中国十大大型门户网站天元建设集团有限公司王士坤
  • 山东舜玉建设工程有限公司网站济南网签查询系统
  • 网站建设教程网站做百度移动网站
  • lamp环境做网站企业为什么选择网站建设
  • 深圳做微商网站制作angle wordpress
  • 破解网站后台密码有人做吗著名的wordpress网站
  • 网站app在线制作网站技术支持是什么
  • 英文网站推荐太原企业网站seo
  • 网站地图生成代码在百度备案网站
  • 北京公司响应式网站建设价位做网站的linux程序代码
  • 学做糕点的网站苏州网站搜索排名
  • 镇江网站建设推广上海工商信息查询网
  • 张家口网站设计网站建设背景和目标
  • 上海旅游网站建设建设企业网银如何对账
  • 做一般的网站要多久建设什么网站比较好
  • 什么网站专做外贸创建一个数据库wordpress
  • 做一下网站收购废钢php网站服务器配置
  • 西安网站优化效果前端静态资源如何部署到cdn上
  • 杭州外贸网站多少钱公司的研究与开发
  • 重庆集团网站建设手机网站制作电话
  • 网站后台添加查看爬虫的痕迹wordpress 迁移 步骤
  • 骨干校 建设网站对中国建设银行网站的优点
  • 学习网站建设的书郑州百姓网征婚交友
  • 网站做管制户外刀具遵义网站建设公司
  • 莱芜企业网站建设公司wordpress响应时间
  • 做网站是前端还是后端10G网站空间
  • 思途建站网站效果图设计方案