Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal {}
- class Cat extends Animal {
- void myaw() {
- System.out.println("myaw!");
- }
- }
- class Dog extends Animal {
- void gav() {
- System.out.println("dog!");
- }
- }
- public class Main {
- public static void main(String[] args) {
- Cat[] cats = { new Cat(), new Cat() };
- Animal[] animals = cats;
- animals[0] = new Dog();
- for (Cat cat: cats) {
- cat.myaw();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement