I use "extends" to create 3 variables in "Dog" class and "Cat" class.
But I failed. Why? What's wrong with my code?
package com.codegym.task.task05.task0527;
/*
Tom and Jerry
*/
public class Solution {
public static void main(String[] args) {
Mouse jerryMouse = new Mouse("Jerry", 12, 5);
Dog dog = new Dog("d", 1, 1);
Cat cat = new Cat("Tom", 1, 1);
}
public static class Mouse {
String name;
int height;
int tail;
public Mouse(String name, int height, int tail) {
this.name = name;
this.height = height;
this.tail = tail;
}
}
public static class Animal {
String name;
int height;
int tail;
}
public static class Dog extends Animal {
public Dog(String name, int height, int tail) {
this.name = name;
this.height = height;
this.tail = tail;
System.out.println(name + " " + height + " " + tail);
}
}
public static class Cat extends Animal {
public Cat(String name, int height, int tail) {
this.name = name;
this.height = height;
this.tail = tail;
System.out.println(name + " " + height + " " + tail);
}
}
}