public abstract class PlayableItem{
private int duration;
protected PlayableItem(int duration){
this.duration = duration;
}
//getters and setters
public abstract String play();
public Song extends PlayableItem(){
private String name = name;
private String title = title;
protected Song(int duration, String name, String title){
super(duration);
this.name = name;
this.title = title;
}
//getters and setters
@Override
public String play(){
return "artist name - " + name + "song title - " + title + "duration - "
+ duration;
}
For some reason I keep getting an error on the Override method, specifically on duration. But my professor wants me to keep the private int field in the abstract class. All the lessons we had on abstract classes used private fields but never actually used as part of the parameter in the subclasses. I can't help but think that we overlooked something very important during our lessons because clearly it seems that the fields in an abstract class is treated differently from regular superclass fields.
Namely, in a regular superclass of Animals that has a private String field type
public class Animals{
private String type;
public Animals(String type){
this.type = type;
}
}
public class Pet extends Animals{
private String color;
public Pet(String type, String color){
super(type);
this.color = color;
}
}
when creating a Pet object, you are required to use the Parent class parameter but for abstract classes it seems different. Can someone explain?