Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active Aug 31, 2021
Embed
What would you like to do?
/**
* 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