Am I using the superclass correctly to access the title, minutes and price?
public class Video extends CollectionItem
{
public Video(String title,
int minutes, double price) {
super(title,minutes,price);
}
public String getTitle() {
return super(title);
}
public int getMinutes() {
return super(minutes);
}
public double getPrice() {
return super(price);
}
public double pricePerMinute() {
return
super(price)/super(minutes);
}
}
here is my superclass can you check to make sure i did everything correctly i am very new to this and i did research i just thought that super() was the correct way
Public class CollectionItem
{
public String title;
public int minutes;
public double price;
public int pages;
public Video(String title,
int minutes, double price) {
this.title = title;
this.minutes = minutes;
this.price = price;
}
public Book(String title,
int pages, double price) {
this.title = title;
this.pages = pages;
this.price = price;
}
public String getTitle() {
return title;
}
public int getPages() {
return pages;
}
public double getPrice() {
return price;
}
public int getMinutes() {
return minutes;
}
}
No, you’re not.
It depends on how the super class is defined. If the price,minutes fields are defined as protected then you access them just by writing their name. So,
Even more likely, is that the super class defines a public getter method such as:
If that is the case, then there’s no need to define a similar method in the subclass since the method from the super class is inherited by the subclass.