Я пытаюсь, чтобы мой класс драйверов наследовал информацию от двух разных классов.Я должен использовать формулу className objectName = new className (входные параметры), чтобы создать экземпляр одного из классов.Но я продолжаю получать символ не распознанная ошибка.
Я не уверен, как я мог решить эту проблему.Я попытался создать оператор импорта, но два других класса являются частью одного пакета.Я также пытался использовать ключевое слово extends, но также noluck
public class Corgi extends Dog {
// additional class variables
private static int weight;
private static int age;
// constructor
public Corgi(String type, String breed, String name, int pounds, int years) {
// invoke Dog class (super class) constructor
super(type, breed, name);
weight = pounds;
age = years;
}
// mutator methods
public static int setWeight(int pounds){
weight = pounds;
return pounds;
}
public static int setAge(int years){
age = years;
return years;
}
// override toString() method to include additional dog information
@Override
public String toString() {
return (super.toString() + "\nThe Corgi is " + age +
" years old and weighs " + weight + " pounds.");
}
}
public class Dog {
// class variables
private static String type;
private static String breed;
private static String name;
private static String topTrick;
// constructor
public Dog(){
type = "none";
breed = "none";
name = "none";
}
// methods
public static String setTopTrick(String trick){
topTrick = trick;
return trick;
}
// method used to print Dog information
public String toString() {
String temp = "\nDOG DATA\n" + name + " is a " + breed +
", a " + type + " dog. \nThe top trick is : " +
topTrick + ".";
return temp;
}
}
public class Main
{
public static void main(String[] args) {
Corgi tricker = new Corgi();
tricker.setTopTrick("Backflip");
System.out.println(tricker);
}
}
Я ожидаю, что основной класс сможет наследовать информацию Corgi с помощью Corgi tricker = new Corgi ();заявление.Но я продолжаю получать сообщение об ошибке:
Main.java: 6: ошибка: не могу найти символ Corgi tricker = new Corgi («Охота», «Шиба», «Симон», 30, 7);
^ символ: класс Корги расположение: класс Главный