Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active August 31, 2021 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minte9/5f005ca840fcb0d546a915b7726ef594 to your computer and use it in GitHub Desktop.
Save minte9/5f005ca840fcb0d546a915b7726ef594 to your computer and use it in GitHub Desktop.
/**
* 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