Created
August 27, 2021 10:45
-
-
Save vogon101/d6bffdb4f9bf2ec56d1dcce474df8e32 to your computer and use it in GitHub Desktop.
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
package pkg; | |
public class Main { | |
public static void main(String[] args) { | |
Dog d = new Dog(); | |
d.woof(); | |
d.scratch(); | |
Dog d1 = new AngryDog(); | |
d1.scratch(); | |
sayHello(d); | |
sayHello(d1); | |
} | |
public static void sayHello(Animal d) { | |
System.out.println("Hello"); | |
d.scratch(); | |
} | |
} | |
class Animal { | |
private String name; | |
public void scratch() { | |
System.out.println("Scratch"); | |
} | |
public String getName() { | |
return name; | |
} | |
} | |
class Dog extends Animal { | |
public String furColour; | |
public void woof(){ | |
System.out.println("Woof"); | |
} | |
} | |
class AngryDog extends Dog { | |
@Override | |
public void scratch() { | |
System.out.println("OW"); | |
} | |
} | |
class Cat extends Animal { | |
private String furColour; | |
public void meow() { | |
System.out.println("Meow"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment