-
vb.net教程之用继承建立一个继承类
用继承建立一个继承类
"Inherits"关键字可以用在使一个类继承另一个类的属性、方法、事件等等,所有的类缺省的都是可以继承的,除非被设置为"NoInheritable"关键字。
下面这个例子定义了两个类,第一个类是一个基础类,并且含有一个属性和两个方法,第二个类从第一个类继承了这个属性和两个方法,重载了第二个方法,并且定义了一个新的属性"intProp2"。
Class Class1
Private intProp1 as Integer
Sub Method1()
Messagebox.Show("这是在基本类中的一个方法")
End Sub
Overridable Sub aMethod()
Messagebox.Show("这是在基本类中的另一个方法")
End Sub
Property Prop1 As Integer
Get
Prop1=intProp1
End Get
Set
intProp1=Value
End Set
End Property
End Class
Class Class2
Private intProp2 As Integer
Inherits Class1
property Prop2 As Integer
Get
Prop2=intProp2
End Get
Set
IntProp2=Value
End Set
End Property
Overrides Sub aMethod()
Messagebox.Show("这是在继承类中的一个方法")
End Sub
End Class
Protected Sub TestInheritance()
Dim C1 As New class1()
Dim C2 As New class2()
C1.Method1()
C2.aMethod()
C2.Method1()
End Sub
当用户运行过程TextInheritance以后,可以看见如下的信息:
“这是在基本类中的一个方法”
“这是在基本类中的另一个方法”
“这是在基本类中的一个方法”
“这是在继承类中的一个方法
"Inherits"关键字可以用在使一个类继承另一个类的属性、方法、事件等等,所有的类缺省的都是可以继承的,除非被设置为"NoInheritable"关键字。
下面这个例子定义了两个类,第一个类是一个基础类,并且含有一个属性和两个方法,第二个类从第一个类继承了这个属性和两个方法,重载了第二个方法,并且定义了一个新的属性"intProp2"。
Class Class1
Private intProp1 as Integer
Sub Method1()
Messagebox.Show("这是在基本类中的一个方法")
End Sub
Overridable Sub aMethod()
Messagebox.Show("这是在基本类中的另一个方法")
End Sub
Property Prop1 As Integer
Get
Prop1=intProp1
End Get
Set
intProp1=Value
End Set
End Property
End Class
Class Class2
Private intProp2 As Integer
Inherits Class1
property Prop2 As Integer
Get
Prop2=intProp2
End Get
Set
IntProp2=Value
End Set
End Property
Overrides Sub aMethod()
Messagebox.Show("这是在继承类中的一个方法")
End Sub
End Class
Protected Sub TestInheritance()
Dim C1 As New class1()
Dim C2 As New class2()
C1.Method1()
C2.aMethod()
C2.Method1()
End Sub
当用户运行过程TextInheritance以后,可以看见如下的信息:
“这是在基本类中的一个方法”
“这是在基本类中的另一个方法”
“这是在基本类中的一个方法”
“这是在继承类中的一个方法
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比