Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class polymor {
- // consider this as animal
- static class animal {
- public void sound() {
- System.out.println("Animal makes sound");
- }
- }
- static class cat extends animal {
- public void sound() {
- System.out.println("meow meow");
- }
- }
- static class dog extends animal {
- public void sound() {
- System.out.println("woof woof");
- }
- }
- static class owl extends animal {
- public void sound() {
- System.out.println("hoot hoot");
- }
- }
- public static void main(String[] args) {
- polymor owl1 = new owl();
- cat eevee = new cat();
- owl1.sound();
- eevee.sound();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement