Total Pageviews

Monday 26 March 2012

How to cast a list in inheritance

For Example:
public class Person {};
public class Student extends Person{};
List<Person> persons=new ArrayList();
List<Student> students=new ArrayList();

persons=students;

how can you assign students to persons? the last line will throw an error.

2 comments:

  1. Change the declarition:
    List persons=new ArrayList();
    Now you can:
    persons=students;

    ReplyDelete
  2. It's a wonderful post and very helpful, thanks for all this information about Java. You are including better information regarding this topic in an effective way.keep it up!!

    android training in chennai

    android online training in chennai

    android training in bangalore

    android training in hyderabad

    android Training in coimbatore

    android training

    android online training

    ReplyDelete