From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Build an employee class

Solution: Build an employee class - Java Tutorial

From the course: Java Object-Oriented Programming

Solution: Build an employee class

(upbeat music) - [Instructor] Let's represent an employee, in Java, with a class. We'll create a new class, call it employee, and give it the appropriate attributes. We'll say it has a name that's a string, a location that's also a string, a double salary, and an age that's an int. These will all be non-static attributes, because they vary based on each employee instance. One might say, all employees are based in a single location, in which case the location might be static. Another option is to make an enum for the location, so there are only a set of places where a given employee might work from. It's all up to you on how you want to represent an employee object in code. To create employees, we'll need a constructor. We'll write Employee, and we'll want to create a custom employee with given name, location, salary, and age attributes, so we'll need to pass those in as parameters, then we'll set up our employee.…

Contents