扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Crystal编译 来源:yesky 2007年11月11日
关键字:
Public | Public类成员没有访问限制。构造public类成员是在类成员名前面使用关键字public,所有人均可访问public成员。例如,Employee类中的PrintSalary方法是一个公有方法,能够被任何人和函数调用。 |
Private | Private类成员只能被类内部访问,使用Private关键字声明私有化类成员。 |
Protected | 保护成员能被类内部成员和他的继承类访问,使用关键字Protected定义保护成员。 |
Friend | 友员访问限制在声明该类的程序中,使用关键字Friend声明一个友员。 |
Protected friend | protected和friend的结合。 |
Listing 7: Class SalaryLevel Public Shared Level1 As Decimal = 35000 Public Shared Level2 As Decimal = 40000 Public Shared Level3 As Decimal = 45000 Public Shared Level4 As Decimal = 50000 Public Shared Level5 As Decimal = 55000 Public Shared Level6 As Decimal = 60000 Public Shared Level7 As Decimal = 65000 Public Shared Level8 As Decimal = 70000 Public Shared Level9 As Decimal = 75000 Public Shared Level10 As Decimal = 80000 End Class |
Listing 8: 使用类的静态成员 Imports System Class SalaryLevel Public Shared Level1 As Decimal = 35000 Public Shared Level2 As Decimal = 40000 Public Shared Level3 As Decimal = 45000 Public Shared Level4 As Decimal = 50000 Public Shared Level5 As Decimal = 55000 Public Shared Level6 As Decimal = 60000 Public Shared Level7 As Decimal = 65000 Public Shared Level8 As Decimal = 70000 Public Shared Level9 As Decimal = 75000 Public Shared Level10 As Decimal = 80000 End Class Class Employee Dim yearlyBonus As Decimal = 4000 Public Sub PrintSalary() ' print the salary to the Console, use ' the static field of SalaryLevel Console.Write(SalaryLevel.Level4) End Sub Public Shared Sub Main() Dim employee As Employee employee = New Employee() employee.PrintSalary() End Sub End Class |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者