Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
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
I have few questions and tell me the answers


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
Comments
Smithers-Jones 1-Dec-11 6:53am    
Repost: http://www.codeproject.com/Questions/293070/how-to-add-employee-list-using-constructor
Reported.
Sergey Alexandrovich Kryukov 1-Dec-11 14:31pm    
Hm. Four reports by now.
Nevertheless, I answered. Hope you will find my solution appropriate :-)
--SA

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.
 
Share this answer
 
Comments
shivani 2013 1-Dec-11 6:49am    
thanx
shivani 2013 1-Dec-11 6:56am    
I am not getting answers thats why i came here
.it would be good if u help me for this
Sergey Alexandrovich Kryukov 1-Dec-11 14:30pm    
I explained what can help you in my solution -- not answering these questions. You are not ready to understand those answers -- just yes. Please come back later when you are more ready, with more mature questions -- we well gladly help.
Sergey Alexandrovich Kryukov 1-Dec-11 14:29pm    
I agree with you, my 5.
The problem is: OP needs systematic education (nearly from scratch), not answers to these questions -- it's just useless.

Please see my solution.
--SA
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.

—SA
 
Share this answer
 
Comments
Manoj K Bhoir 1-Dec-11 23:53pm    
Ok SAKryukov
Defualt Constructor :
VB
Sub New()
     'Your Code
End Sub

Overload Constructor :
VB
Sub New(ByVal Name As String, ByVal Salary As String)
    _Name = Name       '_Name is Private Variable
    _Salary = Salary   '_Salary is Private Variable
End Sub

Proerty :
VB
Public Property Salary() As Decimal
     Get
         Return _Salary   '_Salary is Private Variable
     End Get
     Set(ByVal value As Decimal)
         _Salary = value
     End Set
 End Property

ReadOnly Property :
VB
'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 Get

Add New Employee :
VB
Dim Emp1 As Employee = New Employee 'It create new object of class employee

Add New Employee using Constructor Overloading :
VB
Dim Emp1 As Employee = New Employee("Employee1","10000") 'It create new object of class employee with two parameters

To add List of Employee :
VB
Dim EmployeeList As List(Of Employee)
EmployeeList.Add(Employee1)

To display every Employee in EmployeeList :
VB
For Each item In EmployeeList
  MessageBox.Show(item.ToString())
Next

Last 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 :)
 
Share this answer
 
Comments
fjdiewornncalwe 1-Dec-11 9:44am    
Please don't just give blanket answers to blatant homework/interview questions. If the candidate doesn't know these basic things, do you want to work with them on your team? The idea is to give the OP concepts without doing the actual coding for questions like this.
Sergey Alexandrovich Kryukov 1-Dec-11 14:32pm    
I also explained why this is useless -- in my solution, please see.
--SA
Manoj K Bhoir 1-Dec-11 11:44am    
Ok Marcus Kramer! and Thanks
Sergey Alexandrovich Kryukov 1-Dec-11 14:32pm    
Marcus is right. And it won't really help OP. Please see my solution where I explain why.
--SA

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