mardi 28 avril 2020

Java Class Collect All Child Attributes

I want to create a class that may have its children attributes. For example:

public class Parent {
    private String a;
    private String b;
}
public class ChildA extends Parent {
    private String c;
    private String d;
}
public class ChildB extends Parent {
    private String e;
    private String f;
}

How could Parent have attributes of ChildA when ChildA is passed and ChildB when ChildB is passed? It may be done by get it as a plain Object, however how to do it in more OOP way?

Aucun commentaire:

Enregistrer un commentaire