Given the following class class Main { private static class Vegetable { } privat
ID: 3781412 • Letter: G
Question
Given the following class
class Main {
private static class Vegetable {
}
private static class Carrot extends Vegetable {
}
public static void main(String[] args) {
List<Potato> potatos = new ArrayList<>();
eatVegetable(potatos);
}
private static void eatVegetable(List<Vegetable> fruit) {
}
}
- Please explain why the following code will not compile.
- What change to the signature of the ‘eatVegetable’ method will allow it to accept lists of any types of vegetable (but only lists of type vegetable).
Explanation / Answer
1) you have error in sytax- List<Potato> potatos = new ArrayList<>();
2) Potato class is not defined.
3) eatvegitable should be made public.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.