One of the most popular questions in the interview is, of course, glasses, and you might get a question
like this design a class for simply, which takes a different name during construction of object.
And here's a sell at a property.
So as you can see, we're not getting super strict requirements here, and we have some flexibility
to implement it.
This is why I highly recommend you to think about it and implement it in the best possible way.
So first of all, he'll want to create a class and let's name it, employee, and now as it said, we
need to have a constructor with the ID and name inside.
This is why let's create a constructor and we're getting our age and name and after this were signed
them to this.
Here is our ID, and this name equals name.
So we're getting these two properties, but you can do it better because you must show that you're a
good developer.
This is why it is really nice to check if we're past inside these two properties.
So we can just tell, OK, if we didn't pass ID or we didn't pass name, then we want to throw in there.
This is why I want to throw here New ERA and here inside we can write.
For example, our employee I.D. and name are mandatory because actually this is what it is seen in the
task, and it is nice to cover this feature.
Also, as you can see, we have a line and it has a sell at a property, which actually means we can
set the salary.
It's not like we're getting it in constructor, so we need to Serta and get the functions for our salary.
So first of all, we can define it set salary and it will be a function of a center for salary and we
passing inside our salary and we just store it inside this.
So this Dot's salary equals our salary.
This is not all because we also want to get.
Yes, sure, the salary is available inside our class, but we really want to construct this class in
advanced way, which actually means we want to have some public API and some methods to get our properties.
This is why here I highly recommend it to create get salary and we don't need anything here and we want
to return here.
This dot salary, and it also makes sense to create together for our ad and name.
So here we can create get the method and inside were written in our thesis dot idea and we also can
create here, get named method and it will return our thesis name.
So as you can see, we thought quite a lot about our class and it is implemented as best as we can.
Now here we can try to use it.
So here we are, creating our employee with new employee and we are passing inside ID and name because
they are mandatory and actually we can check it.
We can rely on the page and we are getting employee I.D. and name are mandatory.
And this is nice to check.
So here is our eighty-one and name.
For example, check and now our employee bond through a narrow what we can do now.
We can write employee said salary and work bison, for example, one thousand inside and now we can
check it.
So I will rely on the page and here is our employee with their name and salary, but will also have
a get us.
For example, get salary, will return to our salary and get name will return the name, which actually
means we implemented our class as best as possible.
But now get getting the second task design a class for manager, which is employee and can have a department
property, which actually means here your interviewer want to see extend of our class because we can
create in your class based on our employee class.
This is way here on the bottom.
We can create a new class manager.
And here we want to use extends to take the functionality of our employee class.
And actually, this is almost it.
This will take everything from our employee class, but we also need to create a department.
This is why we just need a center and a getter, just like we did previously.
So let's create here, said Department.
And here inside we are passing department or just name.
And here we are, saving our name inside.
We also need to get us, so get department and we don't need any arguments here and we want to return
our Theaster department.
And actually, it is also super important to have a nice name, several where, as you can see, I am
not naming things like said or just at full or whatever.
I really tried to make the names as production ready as possible by using here, for example, said
department departments.
So it is all clear what it is about, and it really shows on the interview that you are a good developer
and you can write high quality code.
So here we have our said department and get department.
Now let's create our manager.
So we're just creating human nature and we must pass inside as always, idea and name, for example,
John.
And now here we can check our manager so we can make said department and wear person inside department,
for example development.
And now we can check our manager.
So we haven't said department and there is a GED department function, which will return fire at the
department.
This is how typically you will answer questions regarding classes or extension of the classes.