Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active August 31, 2021 12:11
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/603e22a569c4006b1373fc56c882f38e to your computer and use it in GitHub Desktop.
Save minte9/603e22a569c4006b1373fc56c882f38e to your computer and use it in GitHub Desktop.
/**
* Define abstact class Animal
* Class Animal contains two methods, eat() and showName()
* One of the method is abstract
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.setName("MyDog");
System.out.println(d.name); // MyDog
}
}
class Dog extends Animal {
@Override
public void eat() {}
}
/**
* SOLUTION
*/
abstract class Animal {
public String name;
public abstract void eat();
public void setName(String n) {
name = n;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment