public class Father {
public String name;
public Father(String name){
this.name=name;
}
}
public class Son extends Father {
public Son(String name) {
super(name);
}
}
public class Ten {
public static void main(String[] args) {
Father father=new Son("Ramesh");
System.out.println(father.name);
List<? extends Father> list=new ArrayList<Son>();
list.add(father);
for (Father father1:list) {
System.out.println(father1.name);
}
}
}
I am getting this compilation error Error:(11, 16) java: no suitable method found for add(com.adp.quest.Father) method java.util.Collection.add(capture#1 of ? extends com.adp.quest.Father) is not applicable (argument mismatch; com.adp.quest.Father cannot be converted to capture#1 of ? extends com.adp.quest.Father) method java.util.List.add(capture#1 of ? extends com.adp.quest.Father) is not applicable (argument mismatch; com.adp.quest.Father cannot be converted to capture#1 of ? extends com.adp.quest.Father)
Kindly explain why I am getting this on list.add(father)?