There are at least 3 issues with the code below. It is easiest to identify them
ID: 2247102 • Letter: T
Question
There are at least 3 issues with the code below. It is easiest to identify them by first reading the main(). Fix the issues (2 pints each), writing directly near/on the code. Do NOT just describe the fix, you need to write code (4 lines or less) to FIX them: public abstract class Item { private String name: public Item(String name) { this.name = name: } } public class Movie { private int year: public Movie(String name, int year) { super (name, year): } } public class Book extends Item { private String publisher: public Book (String name, String publisher) { this.name name: this.publisher = publisher: } } public class Test { public static void main(String [] args) { List items = new ArrayList (): items.add (new Movie ("Psycho", 1958)): items.add (new Book ("Wonder", "Random House")): } }Explanation / Answer
Corrected Java Classes
public class Movie extends Item { // it should extend the class Item
private int year;
public Movie(String name, int year) {
super(name); // name should be set to the parent class' name
this.year = year;
}
}
public class Book extends Item {
private String publisher;
public Book(String name, String publisher) {
super(name); // parent class' name should be set
this.publisher = publisher;
}
}
All the remaining classes are correct.
Movie.javapublic class Movie extends Item { // it should extend the class Item
private int year;
public Movie(String name, int year) {
super(name); // name should be set to the parent class' name
this.year = year;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.