Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Animal {
- abstract void makeSound();
- public void eat() {
- System.out.println("I can eat.");
- }
- }
- class Dog extends Animal {
- public void makeSound() {
- System.out.println("Bark bark");
- }
- }
- class Main {
- public static void main(String[] args) {
- Dog d1 = new Dog();
- // creating obj of dog class
- d1.makeSound();
- d1.eat();
- }
- }
- // Output
- Bark bark
- I can eat.
Add Comment
Please, Sign In to add comment