r/javahelp • u/Seder777 • Sep 06 '15
I need help
For my assignment I need to do this....DECLARE AN INSTANCE VARIABLE CALLED NAME THAT CAN CONTAIN A VALUE SUCH AS "EGGS"....I have no idea where to start. If someone could help me get started hopefully I can finish the assignment. Thanks everyone
0
Upvotes
1
u/desrtfx Out of Coffee error - System halted Sep 06 '15 edited Sep 06 '15
The statement as such does nothing but assign the parameter that was passed in the constructor (or in any method for that matter) to the class-internal variable (field).
This step is necessary so that the class gets it's data that it needs to work with.
Think about a simple
Employeeclass. Each Employee has aname,employeeId, abaseSalary, and more.In the constructor you give meaningful values to those variables so that later in the program you can calculate the salary based on the
baseSalaryof the specific employee and thehoursWorked(that can come from a different source, like a spreadsheet or similar).