zoukankan
html css js c++ java
抽象类
//
抽象类
//
Visual Studio 允许定义抽象类.抽象类是为了派生类而定义接口的一个类.抽象类从本质上说是抽象的,
//
因为在抽象类基础上建立的所有类都提供了一定的方法和属性.您不能在抽象类中创建对象----只能利用
//
它们来派生新的类
//
抽象类在c#中用abstract 关键字来声明.必须提供的方法与属性用abstract来表明.
//
在vb.net中用MustInherit , MustOverride .
using
System;
namespace
FlashCards
{
/**/
///
<summary>
///
Shape 的摘要说明。
///
</summary>
public
abstract
class
Shape
//
形状
{
public
Shape()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
public
abstract
float
Top
{
get
;
set
;
}
public
abstract
float
Left
{
get
;
set
;
}
public
abstract
float
Area();
public
abstract
float
Perimeter();
}
//
覆盖抽象类成员的每一个成员定义都需要 Overrides(vb.net) 或 override(c#) 关键字.
public
class
CirCle:Shape
{
float
fxCenter,fyCenter,fRadius;
public
CirCle()
{
fxCenter
=
0
;
fyCenter
=
0
;
fRadius
=
0
;
}
public
override
float
Top
{
get
{
return
fxCenter
-
fRadius;}
//
fx
set
{fxCenter
=
value
+
fRadius;}
}
public
override
float
Left
{
get
{
return
fyCenter
-
fRadius;}
//
fy
set
{fyCenter
=
value
+
fRadius;}
}
public
override
float
Area()
{
return
(
float
)(
2
*
System.Math.PI
*
Math.Pow((
double
)fRadius,
2
));
}
public
override
float
Perimeter()
{
return
2
*
fRadius
*
(
float
)System.Math.PI;
}
public
float
Radius
{
get
{
return
fRadius;}
set
{fRadius
=
value;}
}
public
virtual
void
Center(
float
x,
float
y)
{
fxCenter
=
x;
fyCenter
=
y;
}
}
}
查看全文
相关阅读:
分糖果
数字游戏
错误票据
包子凑数
带分数
翻硬币
核桃的数量
快速幂
公倍数与素数筛选
mysql 查询当天当周当月的数据
原文地址:https://www.cnblogs.com/furenjun/p/318423.html
最新文章
YII2 多表关联ar查询副表某字段和
YII2 生成二维码
TP5模型初始化字段
Yii2 with 和 joinWith 的区别
解决select2在bootstrap的modal中默认不显示的问题
yii2 ActiveForm field 添加 html 代码
YII2 自定义规则
linux-centos7服务器下,安装swool并初始一个demo
linux-centos7服务下,对mysql5.7环境配置
Python 第一个程序_1
热门文章
The APK failed to install. Error:Could not parse error string.
support:design:26.1.0
python教程_1
Error:No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
java.lang.UnsupportedOperationException
Retrofit 打印log时,中文会显示类似%E8%BE%BD字符
系统架构设计师 知识点整理
yyyy-MM-dd 转换为年月日
魅族手机USB调试无法打开、log无法打印
打印十字图
Copyright © 2011-2022 走看看