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

类的覆盖

None.gif using  System;
None.gif
None.gif
None.gif
//  继承关键字
None.gif
None.gif
// virtual : 声明基类的某个成员在派生类中能被覆盖
        派生类继承了其基类的成员.如果派生类用同样的签名定义了一个成员,这个派生类成员就会覆盖基类成员.成员的签名包括它的名称,参数列表,参数类型和返回的类型.
       如果一个派生类用同样的名称定义了一个成员,但是定义了与基类不同的参数列表,参数类型或返回类型,派生成员将会重载或者遮蔽该基类成员.如果某个基类成员仍然可用,另一个成员将会重载这个成员.如果派生成员代替了基类成员,另一个成员就会遮蔽这个成员.
        能被覆盖的成员必须被声明为virtual(1).
None.gif

None.gif
None.gif
namespace  FlashCards
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// CirCle 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class CirCle
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
float fxCenter,fyCenter,fRadius;
InBlock.gif
InBlock.gif        
public CirCle()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: 在此处添加构造函数逻辑
InBlock.gif            
//
InBlock.gif
            fxCenter=0;
InBlock.gif            fyCenter
=0;
InBlock.gif            fRadius
=0;
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public float Top
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return fxCenter-fRadius;}//fx
ExpandedSubBlockStart.gifContractedSubBlock.gif
            setdot.gif{fxCenter=value+fRadius;}
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public float Left
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return fyCenter-fRadius;}  //fy
ExpandedSubBlockStart.gifContractedSubBlock.gif
            setdot.gif{fyCenter=value+fRadius;}
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public virtual float Area()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (float)(System.Math.PI *Math.Pow((double)fRadius,2)  );
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public float Perimeter()//计算周长
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif{
InBlock.gif            
return 2*fRadius*(float)System.Math.PI; 
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public float Radius  //半径
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return fRadius;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{fRadius=value;}
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public virtual void Center(float x,float y)  //virtual : 声明基类的某个成员在派生类中能被覆盖
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif{
InBlock.gif            fxCenter
=x;
InBlock.gif            fyCenter
=y;
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif    
public class Sphere:CirCle //球体,圆
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif      
float fCenter;
InBlock.gif        
public Sphere()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            fCenter
=0;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public override float Area()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (float)(4*Math.PI *Math.Pow((double)base.Radius ,2) );  //圆的面积
InBlock.gif

ExpandedSubBlockEnd.gif        }

InBlock.gif        
public new void Center(float x,float y)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Center (x,y,0);
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void Center(float x,float y,float z)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.Center(x,y) ;
InBlock.gif            fCenter
=z;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public float Volume()  //体积
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif{
InBlock.gif            
return (float)((4/3)*System.Math.PI*Math.Pow((double)base.Radius,3));
ExpandedSubBlockEnd.gif        }

InBlock.gif                 
InBlock.gif        
public float Front
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return fCenter-base.Radius ;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{fCenter=value+base.Radius ;}
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif}

None.gif
private   void  Button3_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            CirCle myCircle
=new CirCle();
InBlock.gif            myCircle.Radius 
=2;
InBlock.gif            myCircle.Center(
10,2);
InBlock.gif            Response.Write(
"圆的面积: " +myCircle.Radius.ToString()  +"<br>");
InBlock.gif            Response.Write(
"圆的面积: " +myCircle.Area()+"<br>"); 
InBlock.gif            Response.Write(
"圆的周长: "+myCircle.Perimeter()+"<br>" ) ;
InBlock.gif            Sphere mySphere
=new Sphere();
InBlock.gif            mySphere.Radius 
=10;
InBlock.gif            mySphere.Center(
10,20,25) ;
InBlock.gif            Response.Write(
"mySphere Top   :"+mySphere.Top +"<br>" ) ;
InBlock.gif            Response.Write(
"         Left  :"+mySphere.Left +"<br>" ) ;
InBlock.gif            Response.Write(
"         Front :"+mySphere.Front +"<br>" ) ;
InBlock.gif            Response.Write(
"         volume:"+mySphere.Volume() +"<br>" ) ;
InBlock.gif            Response.Write(
"         surface area  : "+mySphere.Area()+ "<br>" ) ;
InBlock.gif            Response.Write(
"         circumference : "+mySphere.Perimeter() +"<br>" ) ;
InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif        }

相关文章:

  • BGP协议学习精华(二)
  • 工作、激情、挑战
  • 开放源码发展史上的重要事件
  • 3月广州IT媒体杀人游戏比赛,就在本周五晚
  • AJAX淋漓尽致的发挥(Google个性化主页 VS. Windows Live.COM)站在互联网浪尖上窃喜...
  • The C++ Programming Language
  • PDF N-Up Maker:一个把PDF转成小册子或者把多个页面放到一个页面上的工具(免费,免Acrobat,命令行模式)...
  • 界面设计测试规范
  • 如何控制横向和纵向滚动条的显隐?
  • 第一本Enterprise Library书籍上市
  • 智能实验室-贴霸(Postio) 2.5.0.250
  • 利用消息机制实现.NET AOP(面向方面编程)--利用ServerContextSink实现多截获
  • Atlas学习手记(8):调用本地Web Service简单介绍
  • 诊断排除基本的 TCP/IP 网络问题
  • 数学名师沈赫哲----在台大上课的演讲全文!!
  • 分享一款快速APP功能测试工具
  • 【跃迁之路】【641天】程序员高效学习方法论探索系列(实验阶段398-2018.11.14)...
  • create-react-app项目添加less配置
  • C学习-枚举(九)
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • ES2017异步函数现已正式可用
  • gops —— Go 程序诊断分析工具
  • javascript 哈希表
  • Markdown 语法简单说明
  • MYSQL如何对数据进行自动化升级--以如果某数据表存在并且某字段不存在时则执行更新操作为例...
  • RxJS 实现摩斯密码(Morse) 【内附脑图】
  • vue-loader 源码解析系列之 selector
  • vue自定义指令实现v-tap插件
  • 阿里云购买磁盘后挂载
  • 从setTimeout-setInterval看JS线程
  • 区块链将重新定义世界
  • 如何用vue打造一个移动端音乐播放器
  • 试着探索高并发下的系统架构面貌
  • 在Docker Swarm上部署Apache Storm:第1部分
  • 正则学习笔记
  • Java总结 - String - 这篇请使劲喷我
  • # 透过事物看本质的能力怎么培养?
  • #define,static,const,三种常量的区别
  • #Spring-boot高级
  • #预处理和函数的对比以及条件编译
  • (ctrl.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“
  • (LNMP) How To Install Linux, nginx, MySQL, PHP
  • (附源码)ssm码农论坛 毕业设计 231126
  • (附源码)计算机毕业设计SSM保险客户管理系统
  • (更新)A股上市公司华证ESG评级得分稳健性校验ESG得分年均值中位数(2009-2023年.12)
  • (六)vue-router+UI组件库
  • (算法)前K大的和
  • (转)Android中使用ormlite实现持久化(一)--HelloOrmLite
  • (转)fock函数详解
  • (转)JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • *p=a是把a的值赋给p,p=a是把a的地址赋给p。
  • . NET自动找可写目录
  • ./configure,make,make install的作用(转)
  • ./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object fil