I'm trying to create a text-based game for class and i'm stuck on trying to get my main class, GCPUAPP, to read from my Artifact class.
Here's the code i've inputed for the GCPUAPP class:
Artifact artifact=new Artifact();
artifact.name="Harry Potter and the Deathly Hallows";
artifact.description="Harry and his friends save the qizarding world again";
r1.contents=artifact;
dialog();
It's giving me an error on "new Artifact". Here's the code I have on Artifact:
public abstract class Artifact{
String name, description;
public String toString(){
return name;
}
I'm new to Java so I am completely stuck.
You can't create an instance of an abstract class
Artifact artifact=new Artifact();
That is the point of abstract classes. Only non-abstract classes that inherit the abstract class can be instanced as object.
Either remove the
abstract
notation from your class definition, or create another class that inheritsArtifact
and call the constructor as thisArtifact artifact=new MyNewArtifact();