Skip to content

Instantly share code, notes, and snippets.

@vogon101
Created August 27, 2021 10:45
Show Gist options
  • Save vogon101/d6bffdb4f9bf2ec56d1dcce474df8e32 to your computer and use it in GitHub Desktop.
Save vogon101/d6bffdb4f9bf2ec56d1dcce474df8e32 to your computer and use it in GitHub Desktop.
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