Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Animal {
- public abstract void noise();
- }
- class Dog extends Animal {
- public void noise() {
- System.out.println("Woof!");
- }
- }
- class Cat extends Animal {
- public void noise() {
- System.out.println("Nyan");
- }
- }
- public class Test {
- public static void main(String[] args) {
- Dog rover = new Dog();
- Cat roverCat = convert(rover);
- roverCat.noise();
- }
- public static Cat convert(Dog d) {
- Cat[] cats = new Cat[100];
- Animal[] animals = cats;
- animals[0] = d;
- return cats[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement