因此,我拿了一些我的科普教授的示例類,並試圖編譯它們以瞭解更多關於它的知識,但是我得到了「找不到符號」的錯誤。所有文件都在同一個文件夾中。任何人都可以告訴我如何解決這個問題或發生了什麼?給我「抽象符號未找到」的子類抽象類的錯誤
這裏是抽象類:
package abstractclass;
/**
The Element class is introduced to illustrate the use of
abstract classes. In this revised version of the PersonSet
class example, the Person class will inherit from this
abstract class. The purpose of the abstract class Element
is to introduce the "common class protocol" for all of its
subclasses. That common class protocol is introduced using
abstract as well as fully implemented methods. The abstract
methods are:
readIn
display
equals
clone
In addition, the abstract class Element fully implements the
getClassName method.
*/
public abstract class Element
{
// Access method
/**
The getClassName method returns the name of the calling object's
class.
@return the name of the calling object's class
*/
public String getClassName()
{
// Local data ...
String resultStr;
// Result of applying toString method to
// the calling object
int whereAt; // Where the @ symbol is in resultStr
// Logic ...
resultStr = this.toString();
whereAt = resultStr.indexOf('@');
resultStr = resultStr.substring(0,whereAt);
whereAt = resultStr.indexOf('.');
return resultStr.substring(whereAt + 1);
}
// Abstract methods readIn, display, equals and clone.
// A direct subclass must implement these abstract methods
// unless the direct subclass is itself declared "abstract"
public abstract void readIn();
public abstract void display();
public abstract boolean equals(Element dobj);
public abstract Element clone();
}
這裏是子類人:
package abstractclass;
import java.util.Scanner;
import java.util.*;
public class Person extends Element
{
private String name;
private String eMail;
public Person()
{
name = "";
eMail = "";
}
public Person (String aName)
{
name = new String(aName.toUpperCase());
}
public Person (Person originalPerson)
{
name = new String(originalPerson.name);
eMail = new String(originalPerson.eMail);
}
public String getName()
{
return new String(name);
}
public String getEMail()
{
return new String(eMail);
}
public void setName(String aName)
{
name = new String(aName.toUpperCase());
}
public void setEMail(String anEMail)
{
eMail = new String(anEMail);
}
public void readIn()
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Name: ");
name = keyboard.nextLine().toUpperCase();
System.out.print("E-Mail: ");
eMail = keyboard.nextLine();
}
public void display()
{
System.out.println("Name: " + name);
System.out.println("E-mail: " + eMail);
}
public boolean equals(Element otherPerson)
{
return name.equals(((Person) otherPerson).name);
}
public Element clone()
{
Person theClone = new Person();
theClone.name = new String(name);
theClone.eMail = new String(eMail);
return theClone;
}
這裏是它給我的錯誤,當我嘗試編譯Person類:
Person.java:13: error: cannot find symbol
public class Person extends Element
^
symbol: class Element
Person.java:147: error: cannot find symbol
public boolean equals(Element otherPerson)
^
symbol: class Element
location: class Person
Person.java:158: error: cannot find symbol
public Element clone()
^
symbol: class Element
location: class Person
3 errors
剛一說明:從'Object'類,而不是覆蓋'equals'方法實現你自己的。 –
你是如何編譯的? –