Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote