Last active
August 31, 2021 12:07
-
-
Save minte9/5f005ca840fcb0d546a915b7726ef594 to your computer and use it in GitHub Desktop.
Java / OOP / Inheritance - https://www.minte9.com/java/oop-introduction-inheritance-1182
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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