Can a parent class array hold children class objects in Java? -


i have parent class named student. have created 2 children class permanentstudent , casualstudent extending this. have written constructors both extended child classes (both child class have own constructors). now, making array of size 10 of students out of 4 permanent students , 6 casualstudents. this, did follows:

student[] = new student[10]; int count; 

now, wish fill array 4 permanent students objects , 6 casual student objects information through constructor. following,

for (count = 0; count < 4; count++) {     a[count] = new permanentstudent(a,b,c); // invoking constructor } (count = 4; count < 10; count++) {     a[count] = new casualstudent(x,y); // invoking constructor of other class } 

but gives me compilation error. going wrong in this? thanks!

assignment base base = new sub() or base[i] = new sub() in case legal in java. problem in constructors, check no-arguments constructor exists in student.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -