I have an already created Person class with its respective attributes; eventually a person can turn into an Employee.
Using inheritance, Employee can be a subclass of Person. How can you transform (“specialize”) this Person to an Employee without the need of transfering all of its attributes to the new Employee class ?
Is it better to have an independent (regarding inheritance) Employee class with an attribute of Person type (as in often seen in DB) ?
Thanks in advance!
This is not possible in Java. An object has a type, and can’t acquire a new one. If it’s a Person it will always be a Person, and will never be an employee. You can create a new object, of type Employee, from a Person, though :