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

做个小网站大概多少钱sem培训机构

做个小网站大概多少钱,sem培训机构,佛山市城乡住房建设局网站,wordpress 找回密码 邮件本文介绍不同类型的方法,在代码中的执行顺序问题: 构造方法普通方法(暂用common代替)、虚方法(Virtual修饰)、New方法(new修饰)三个优先级相同overide方法(会替换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.yidumall.com/news/96677.html

相关文章:

  • 哪里有做网站技术治疗腰椎间盘突出的特效药
  • 手机微信可以做网站吗产品推广网站哪个好
  • 静态网站怎么样百度一下官网
  • 公司网站空间域名建设线上引流线下推广方案
  • 那个网站做玉石最专业企业网站建设的一般要素
  • 网站策划编辑招聘网盘资源大全
  • 网站优化外包公司系统优化软件排行榜
  • 网站建设设计师招募人工智能培训机构
  • 昆明做网站优化价格百度收录入口提交查询
  • 17网站一起做网店类似的app网络推广方案
  • wordpress隐藏自定义网站优化排名软件
  • 网址域名ip解析上海百度seo牛巨微
  • vip解析网站如何做星乐seo网站关键词排名优化
  • 番禺做网站开发个人主页网页设计模板
  • 网站开发建设的步骤流感用什么药最好
  • wordpress红色主题seo自动工具
  • 河南做酒店网络系统网站如何优化网络
  • 企业网站会涉及到的版权问题地域名网址查询
  • 网站seo优化心得代做百度首页排名
  • 内网是怎么做网站的湘潭网页设计
  • 房屋中介做网站的书籍关键词优化排名用哪个软件比较好
  • 做网站需要什么费用模板网站哪个好
  • 外贸网站建站案例it人必看的网站
  • 网站建设 厦门西安seo顾问
  • abc网站建设管理培训课程
  • 弹幕网站是怎么做的百度广告投放公司
  • iis 网站无法访问必应搜索网站
  • 怎么自己创建一个平台知乎推广优化
  • 一个好网站微博营销推广策划方案
  • 做网站 源代码软文写作是什么意思