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;
}
}
}
查看全文
相关阅读:
【LeetCode】306. Additive Number
【LeetCode】49. Group Anagrams
【LeetCode】233. Number of Digit One
【LeetCode】73. Set Matrix Zeroes
【LeetCode】284. Peeking Iterator
【LeetCode】241. Different Ways to Add Parentheses
【LeetCode】289. Game of Life
新版Java为什么要修改substring的实现
计算机中整数加法满足结合律吗
双色球中奖概率分析
原文地址:https://www.cnblogs.com/furenjun/p/318423.html
最新文章
web三大组件的加载顺序
SpringMVC源码剖析(五)-消息转换器HttpMessageConverter
Spring-MVC理解之二:前置控制器
Spring-MVC理解之一:应用上下文webApplicationContext
Spring MVC @RequestParam @RequestHeader @CookieValue用法
Servlet容器Tomcat中web.xml中url-pattern的配置详解[附带源码分析]
适配器设计模式详解
JDK Collection 源码分析(3)—— Queue
MyBatis源码分析(5)——内置DataSource实现
QR 二维码总结
热门文章
Struts2 拦截器配置以及实现
Struts2 更改校验配置文件位置
MyBatis源码分析(4)—— Cache构建以及应用
MyBatis源码分析(3)—— Cache接口以及实现
MyBatis Cache配置
Service Provider Interface
Java Annotation概述
【LeetCode】332. Reconstruct Itinerary
【LeetCode】187. Repeated DNA Sequences
【LeetCode】60. Permutation Sequence
Copyright © 2011-2022 走看看