is it possible to access child class in parent?
e. g. I want the output of the following code tobe “red blue”.
class Color {
public final void printName() {
System.out.println(__Something_Here!!!__.class.getSimpleName());
}
}
class Red extends Color;
class Blue extends Color;
main() {
Red red = new red();
Blue blue = new blue();
red.printName();
blue.printName();
}
You can use
getClass()to return the class object for any object.See the Javadoc for
getClass()for details