我创建了一个名为employee的类,其成员ID,名称,薪水.我在此回答的几个问题我不确定,请检查一下 我有几个问题,请告诉我答案 Q 1)默认的构造函数是什么? 回答:
子 新建() 结束 子Q 2)编写一个重载的构造函数,该构造函数传递雇员的姓名和薪水? 答案:
Sub 新( ByVal name1 As 字符串, ByVal 薪金1 按 十进制) 名称=名称1 薪水=薪水1 结束 子Q 3)编写工资的getter和setter方法 ans:
属性 salvage1() As 十进制 获取 薪水1 =薪水 结束 获取 设置( ByVal 值 As 十进制) 薪水=价值 结束 设置 结束 属性问题4)只为ID写一个吸气剂? 回答:
只读 属性 id1() As 十进制 获取 id1 = id 结束 获取问题5)创建员工列表. 我不知道答案. 问题6)使用默认构造函数将新员工添加到列表中 我不知道答案. 问题7)使用重载的构造函数将新员工添加到列表中 回答:
私有 emp As 员工 emp = 新员工(txtid.Text,txtname.Text,txtsalary.Text)txtid,txtname,txtsalary是表单上的文本框 问题8)编写将遍历员工列表并输出其薪水的代码 我不知道它的答案 问题9)如果重载表单的构造函数,应该首先调用哪个函数? 我不知道它的答案 请查看并提供相关答案 thanx 问候
解决方案就像面试试卷一样,您惨遭失败. 如果您搜索Google或读一本书,这会更好,那么您会找到所有答案.
面试问题可能会在一定程度上帮助您了解该技术. .但是考虑面试问题以学习任何东西只是浪费时间.您需要真正的教育,而不是面试培训.而且您显然落后了.因此,请帮自己一个忙:停止问无用的问题并学习一些编程-几乎是从头开始.当然,除了扎根于职业之外,别无他法.
Defualt构造函数: 子 新建() ' 您的代码 结束 子
重载构造函数:
Sub 新建( ByVal 名称 As 字符串, ByVal 薪金 As 字符串) _Name =名称' _ Name是私有变量 _Salary =薪金' _ Salary是私有变量 结束 子财产:
公共 属性 Salary()作为 十进制 获取 返回 _Salary ' _ Salary是私有变量 结束 获取 设置( ByVal 值 As 十进制) _Salary =值 结束 设置 结束 属性ReadOnly属性:
' 我们只能读取ReadOnly属性的值,而不能设置 公共 只读 属性 Id() As 十进制 获取 返回 _ID ' _ Id为私有变量 结束 获取添加新员工:
Dim Emp1 As 员工= New 员工' 它将创建员工类的新对象使用构造函数重载添加新员工:
Dim Emp1 As 员工= New Employee(" Employee1" , " 10000" )' 它会创建新的具有两个参数的班级雇员的对象要添加员工列表:
Dim EmployeeList As 列表( 员工) EmployeeList.Add(员工1)显示EmployeeList中的每个Employee:
对于 每个项目在 EmployeeList MessageBox.Show(item.ToString()) 下一步最后一个问题是错误的.虽然Form Loaded没有调用任何函数,但仅调用了它的构造函数,或者Form_Load被调用了bt,这不是一个函数.它是一个事件:)
I have created a class named employee with its members id,name,salary.I have few questions in this whose answer i am not confident .Please check it I have few questions and tell me the answers Q 1 ) what will be its default constructor? ans:
Sub New() End SubQ 2 ) write an overloaded constructor that passes the employees name and salary? ans:
Sub New(ByVal name1 As String, ByVal salary1 As Decimal) name = name1 salary = salary1 End SubQ 3 ) write getter and setter method for salary ans:
Property salary1() As Decimal Get salary1 = salary End Get Set(ByVal value As Decimal) salary = value End Set End PropertyQ 4 ) write a getter only for the id? ans:
ReadOnly Property id1() As Decimal Get id1 = id End GetQ 5 ) create a list of employees. i don''t know its answer. Q 6 ) add a new employee to the list using default constructor i don''t know its answer. Q 7) Add a new employee to the list using overloaded constructor ans:
Private emp As Employee emp = New Employee(txtid.Text, txtname.Text, txtsalary.Text)txtid,txtname,txtsalary are textboxes on form Q 8 ) write the code that would loop through employee list and output their salary I don''t know its answer Q 9 ) what function should be called first if overloading a form''s constructor? I don''t know its answer please see to it and provide me relevant answers thanx regards
解决方案 Looks like interview question paper in which you failed miserably. It would be better if you search google or read a book, you''ll find all answers.Interview question might help to reveal the level of understanding of the technology, to a limited extent. But considering interview question for learning anything is just a waste of time. You need real education, not interview training. And you apparently well behind. So, please do yourself a great favor: stop asking useless questions and learn some programming — pretty much from scratch. Nothing else can help you, except taking a different career root, of course.Overload Constructor :
Sub New(ByVal Name As String, ByVal Salary As String) _Name = Name '_Name is Private Variable _Salary = Salary '_Salary is Private Variable End SubProerty :
Public Property Salary() As Decimal Get Return _Salary '_Salary is Private Variable End Get Set(ByVal value As Decimal) _Salary = value End Set End PropertyReadOnly Property :
'We can only read the value of ReadOnly Property can not Set Public ReadOnly Property Id() As Decimal Get Return _ID '_Id is Private Variable End GetAdd New Employee :
Dim Emp1 As Employee = New Employee 'It create new object of class employeeAdd New Employee using Constructor Overloading :
Dim Emp1 As Employee = New Employee("Employee1","10000") 'It create new object of class employee with two parametersTo add List of Employee :
Dim EmployeeList As List(Of Employee) EmployeeList.Add(Employee1)To display every Employee in EmployeeList :
For Each item In EmployeeList MessageBox.Show(item.ToString()) NextLast question is wrong.While Form Loaded no function is called only it''s constructor will be called or Form_Load gets called bt it is not a function.It''s an Event :)
更多推荐
如何在Windows窗体中使用构造函数
发布评论