Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active Aug 31, 2021
Embed
What would you like to do?
/**
* Define Dog class using supertype Animal
* Use safeguard annotation.
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.test(); // Dog
}
}
class Animal {
public void test() {
System.out.println(
this.getClass().getSimpleName()
);
}
}
/**
* SOLUTION
*/
class Dog extends Animal {
@Override
public void test() {
super.test();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment