Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 and tell me the answers
here are the questions


Q 1 ) what will be its default constructor?
ans:
VB
Sub New()

   End Sub





Q 2 ) write an overloaded constructor that passes the employees name and salary?
ans:
VB
Sub New(ByVal name1 As String, ByVal salary1 As Decimal)

        name = name1
        salary = salary1
  End Sub







Q 3 ) write getter and setter method for salary

ans:
VB
Property salary1() As Decimal
        Get
            salary1 = salary
        End Get
        Set(ByVal value As Decimal)
            salary = value
        End Set
    End Property





Q 4 ) write a getter only for the id?

ans:
VB
ReadOnly Property id1() As Decimal
        Get

            id1 = id
        End Get





Q 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:
VB
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
Posted
Updated 1-Dec-11 3:26am
v3
Comments
Richard MacCutchan 1-Dec-11 9:25am    
This is obvious homework and it looks like you are far from ready to do it. Go back to your VB.NET notes/references.

try this:

Private emp As Employee
emp = New Employee( txtname.Text, txtsalary.Text)


you dont have a constractor that get 3 arguments!

you can also add to your constractor:

Sub New(ByVal  id1 as Decimal, ByVal name1 As String, ByVal salary1 As Decimal)

        name = name1
        salary = salary1
        id=id1
  End Sub
 
Share this answer
 
v2
Comments
RaviRanjanKr 1-Dec-11 10:02am    
Always wrap your code in "Pre" tag.
It's Very Simple.Try this code :
VB
'If Employee is the Class
Dim Employee1 As Employee = New Employee("Name","Salary")
Dim EmployeeList As List(Of Employee)
EmployeeList.Add(Employee1)

I hope it will help you. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900