noteBook2.10-C#基础第十天

本文详细介绍了面向对象编程中的继承机制,包括父类与子类的关系、继承的特性、如何解决构造函数冲突等问题,并解释了访问修饰符Protected的作用。

继承:

当需要在一些类中重复写相同的成员时,可以将这些重复的成员单独封装到一个类中,作为这些类的父类。

父类         基类

子类         派生类

1.子类继承了父类的属性和方法,但子类没有继承父类的私有字段;

2.子类没有继承父类的构造函数,但是子类会默认调用父类无参数的构造函数,创建父类对象,让子类可以使用父类的成员;所以如果在父类中重新写了一个有参的构造函数,则无参的被替代,子类调用不到无参的构造函数,会报错;

         解决方法:

         1.在父类中重写一个无参的构造函数;

         2.在子类中显示的调用父类有残构造函数,使用关键字:base().

继承的特性:

1.单根性:一个子类只能有一个父类;

2.传递性:

new:

base:

里氏转换:

1.子类可以赋值给父类;

2.如果父类中装的是子类对象,可以将这个父类强制转为子类对象;

         Person(父)Student(子)

         Person      p=new Student();//1

         Student    s=(Student)p;//2

3.里氏转换是否成功:

         is:如果转换成功,返回true,反之false

                  if(p   is      Student){}

         as:如果转换成功,返回相应对象,否则返回null

                   Student    t=P   as     Student;

访问修饰符Protected:

受保护的,可以在当前类的内部及该类的子类中访问。

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace NoteBook { /// <summary> /// About 的摘要说明。 /// </summary> public class About : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public About() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(About)); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.ForeColor = System.Drawing.Color.Red; this.label1.Image = ((System.Drawing.Image)(resources.GetObject("label1.Image"))); this.label1.Location = new System.Drawing.Point(0, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(496, 128); this.label1.TabIndex = 0; this.label1.Text = "label1"; // // label2 // this.label2.Font = new System.Drawing.Font("华文新魏", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label2.Location = new System.Drawing.Point(16, 147); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(192, 32); this.label2.TabIndex = 1; this.label2.Text = "记事本编辑器"; // // label3 // this.label3.Font = new System.Drawing.Font("华文行楷", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label3.ForeColor = System.Drawing.Color.RoyalBlue; this.label3.Location = new System.Drawing.Point(16, 224); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(232, 24); this.label3.TabIndex = 2; this.label3.Text = " 版权所有,翻版必究!"; // // label4 // this.label4.Font = new System.Drawing.Font("华文新魏", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label4.Location = new System.Drawing.Point(240, 151); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(248, 32); this.label4.TabIndex = 3; this.label4.Text = "计算机3063班 C#课程设计 "; // // label5 // this.label5.Image = ((System.Drawing.Image)(resources.GetObject("label5.Image"))); this.label5.Location = new System.Drawing.Point(256, 197); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(240, 64); this.label5.TabIndex = 4; // // About // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(496, 262); this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.ForeColor = System.Drawing.Color.Red; this.Name = "About"; this.Text = "关于我的记事本"; this.ResumeLayout(false); } #endregion } }
### 如何使用 `jupyter notebook --no-browser` 参数运行服务而不自动打开浏览器 为了防止 Jupyter Notebook 自动打开默认浏览器,可以使用参数 `--no-browser` 来启动服务。此参数的作用是禁用自动打开浏览器的行为[^1]。 以下是具体的实现方法: #### 方法一:直接使用 `--no-browser` 参数 可以通过以下命令启动 Jupyter Notebook 服务并禁用浏览器自动打开功能: ```bash jupyter notebook --no-browser ``` 如果需要指定端口号,则可以在上述基础上增加 `--port` 参数。例如,在端口 9999 上启动服务: ```bash jupyter notebook --no-browser --port 9999 ``` 这一步骤确保了服务不会尝试寻找可用的浏览器,并且允许手动通过 URL 访问服务[^3]。 #### 方法二:结合 SSH 隧道连接远程服务器 当在远程服务器上启动 Jupyter Notebook 并希望避免因缺少浏览器而导致错误时,可以按照如下方式操作: 1. **在远程服务器上启动 Jupyter Notebook** 使用 `--no-browser` 和 `--port` 参数启动服务。例如: ```bash jupyter notebook --no-browser --port=8889 ``` 2. **建立本地到远程服务器的 SSH 隧道** 在本地机器上执行以下命令以创建隧道: ```bash ssh -N -f -L localhost:8836:localhost:8889 username@remote_server_ip ``` 这里的 `-L` 参数指定了本地端口 (`8836`) 映射到远程服务器上的端口 (`8889`)。`username` 替换为实际用户名,`remote_server_ip` 替换为服务器 IP 地址[^5]。 3. **通过本地浏览器访问服务** 打开浏览器并在地址栏输入以下内容访问 Jupyter Notebook: ``` http://localhost:8836 ``` 这种方法不仅解决了无法自动打开浏览器的问题,还提供了安全的方式访问远程服务器上的 Jupyter Notebook 实例[^4]。 --- ### 注意事项 - 如果未设置密码或令牌 (token),首次访问时可能会提示输入 token。该 token 可以从启动日志中获取。 - 当遇到类似 `[W 10:05:26.060 NotebookApp] No web browser found: could not locate runnable browser.` 的警告信息时,说明当前环境确实不存在支持的浏览器实例。此时无需担心,因为已通过 `--no-browser` 参数显式关闭了浏览器开启行为[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值