⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base class with a virtual method.htm

📁 点net代码20个
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Base Class With a Virtual Method</title>
</head>

<body background="../basic3.gif">

<table border="0" cellspacing="0" width="596">
  <tr>
    <td>
      <p align="center"><font color="#FF0000" size="4"><b>Base Class With a 
      Virtual Method</b></font></td>
  </tr>
  <tr>
    <td></td>
  </tr>
  <tr>
    <td><font color="#0000ff" size="2">using</font><font size="2"> System;<br>
      <br>
      </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">class</font><font size="2"> 
      DrawingObject<br>
      {<br>
      </font><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;</font><font size="2"> 
      </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">virtual</font><font size="2"> 
      </font><font color="#0000ff" size="2">void</font><font size="2"> Draw()<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;I'm 
      just a generic drawing object.&quot;);<br>
      &nbsp;&nbsp;&nbsp; }<br>
      }</font></td>
  </tr>
  <tr>
    <td>Listing 9-1 shows the DrawingObject class.&nbsp; This will be the base 
      class for other objects to inherit from.&nbsp; It has a single method 
      named Draw().&nbsp; The Draw() method has a virtual modifier.&nbsp; The 
      virtual modifier indicate to derived classes that they can override this 
      method.&nbsp; The Draw() method of the DrawingObject class performs a 
      single action of printing the statement, &quot;I'm just a generic drawing 
      object.&quot;, to the console.</td>
  </tr>
  <tr>
    <td>
      <h5>Listing 9-2.&nbsp; Derived Classes With Override Methods:&nbsp; 
      Line.cs, Circle.cs, and Square.cs</h5>
    </td>
  </tr>
  <tr>
    <td><font color="#0000ff" size="2">using</font><font size="2"> System;<br>
      <br>
      </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">class</font><font size="2"> 
      Line : DrawingObject<br>
      {<br>
      &nbsp;</font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">override</font><font size="2"> 
      </font><font color="#0000ff" size="2">void</font><font size="2"> Draw()<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;I'm a 
      Line.&quot;);<br>
      &nbsp;&nbsp;&nbsp; }<br>
      }<br>
      <font color="#0000ff" size="2"><br>
      public</font> <font color="#0000ff" size="2">class</font> Circle : 
      DrawingObject<br>
      {<br>
      <font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;</font> <font color="#0000ff" size="2">public</font> 
      <font color="#0000ff" size="2">override</font> <font color="#0000ff" size="2">void</font> 
      Draw()<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;I'm a 
      Circle.&quot;);<br>
      &nbsp;&nbsp;&nbsp; }<br>
      }<br>
      <font color="#0000ff" size="2"><br>
      public</font> <font color="#0000ff" size="2">class</font> Square : 
      DrawingObject<br>
      {<br>
      <font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;</font> <font color="#0000ff" size="2">public</font> 
      <font color="#0000ff" size="2">override</font> <font color="#0000ff" size="2">void</font> 
      Draw()<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;I'm a 
      Square.&quot;);<br>
      &nbsp;&nbsp;&nbsp; }<br>
      }</font></td>
  </tr>
  <tr>
    <td></td>
  </tr>
</table>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -