Should Abstract Class Have Getters and Setters?

Yes, they should. Your base class is simply a data bag and it declares two fields: type and color . It is totally fine to declare those fields setters and getters in the base class only.

Can we use getters and setters in abstract class?

Like a normal (concrete) class, abstract class can have constructors. But those can only be called from constructor of derived class by calling super() method. Abstract class can have data members, getter and setter methods.

Should you always have getters and setters?

Using getters and setters, is always, in my opinion good practice. One thing you should avoid is to have external entities mess with the internal structure of your class at will. Typical example, consider having a dateOfBirth parameter.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.