There is an abstract class:
public abstract class SomeClass { String description; public String getDescription() { return description; } }
It has many subclasses, for example:
public class SubClass extends SomeClass { public SubClass() { description = "description"; } }
Each subclass must have a description
field that will be initialized when the object is created.
Did I implement the logic correctly? The idea is that in an abstract class, the field must be declared with the private
modifier in order not to break encapsulation.
UPD: As an option, you can make such an implementation, it looks more correct, but for some reason confuses me.
public abstract class SomeClass { private String description; public void setDescription(String description) { this.description - description; } public String getDescription() { return description; } } public class SubClass extends SomeClass { public SubClass() { setDescription("description"); } }