zoukankan      html  css  js  c++  java
  • VB 总结类、对象、封装的含义

    (1)创建学生Student类,它包含三个属性:整型属性学号(NO)、字符型属性姓名(Name)、日期型属性生日(BirthDay),一个输出的方法PrintInformation,其中,输出信息包含学号、姓名、生日。

    (2)把1题中增加年龄(Age)属性,该属性只读,输出信息为:学号、姓名、年龄。

    (3)把2题中定义一个构造函数,该构造函数可以包含(学号、姓名、生日)


    Public Class Students
    Dim intNo As Integer
    Dim strName As String
    Dim datBirthday As Date

    Public Structure StudentsInfo
    Dim NO As Integer
    Dim Name As String
    Dim Birthday As Date
    End Structure

    Public Sub New()
    intNo = 0
    strName = ""
    datBirthday = Now
    End Sub

    Public Function PrintInformation() As StudentsInfo
    Dim stuInformation As StudentsInfo
    With stuInformation
    .NO = intNo
    .Name = strName
    .Birthday = datBirthday
    End With

    Return stuInformation
    End Function

    Public Property NO()
    Get
    Return intNo
    End Get
    Set(ByVal value)
    intNo = value
    End Set
    End Property

    Public Property Name()
    Get
    Return strName
    End Get
    Set(ByVal value)
    strName = value
    End Set
    End Property

    Public Property BirthDay()
    Get
    Return datBirthday
    End Get
    Set(ByVal value)
    datBirthday = value
    End Set
    End Property
    End Class

    Public Class StudentsAddAge
    Inherits Students
    Dim intAge As Integer

    Public Structure StudentsInfoAddAge
    Dim NO As Integer
    Dim Name As String
    Dim Age As Integer
    End Structure

    Public Sub New()
    intAge = 0
    End Sub

    Public Property Age()
    Get
    Return intAge
    End Get
    Set(ByVal value)
    intAge = value
    End Set
    End Property

    Public Overloads Function PrintInformation(ByVal isPrintAge As Boolean) As StudentsInfoAddAge
    Dim stuInformation As StudentsInfoAddAge
    With stuInformation
    .NO = MyBase.NO
    .Name = MyBase.Name
    .Age = intAge
    End With
    Return stuInformation
    End Function
    End Class

    Public Class StudentsSubNew
    Inherits StudentsAddAge
    Public Sub New(ByVal NO As Integer, ByVal Name As String, ByVal BirthDay As Date)
    MyBase.NO = NO
    MyBase.Name = Name
    MyBase.BirthDay = BirthDay
    End Sub
    End Class
  • 相关阅读:
    join()方法作用
    多线程的运行状态
    守护线程和非守护线程
    多线程快速入门
    Spring Boot2.0之注解方式启动Springmvc
    Spring Boot2.0之 原理—创建内置Tomcat容器
    Spring Boot2.0之纯手写框架
    Sprin Boot2.0之整合Mybatis整合分页插件
    linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制)
    PHP编程效率的20个要点
  • 原文地址:https://www.cnblogs.com/hannover/p/2514032.html
Copyright © 2011-2022 走看看