Abstract class in a statement, please help experts explain how to understand

Category: Java SE
2008-12-28 02:00:18

Sponsored Links

abstract class Person
class Student extends Person
class Employee extends Person

As shown above, I have defined an abstract superclass Person and two concrete subclasses Employee and Student.
Person [] people = new Person [2];
/ / feeling a little difficult to understand this sentence I hope you were able to analyze in detail explain, thank
people [0] = new Employee (...);
people [1] = new Student (...);

Sponsored Links

2008-12-28 02:02:32
Is this new generation array instead of the Person object.
you might be an abstract class can not be instantiated to phrase confused
2008-12-28 02:11:27
first need to know to use the parent class reference can point to a subclass object, you define an array of examples, it should be so understood

>> Person [] people = new Person [2];
definition creates an array object, people are pointing to an array of object references, instead of pointing to the Person object references,
each element in the array is a reference to the Person type, time also does not refer to specific objects.

> ;> people [0] = new Employee (...);
>> people [1] = new Student (...);
The two are actually references to the Person type objects and Student Employee object belongs to upcast.

2008-12-28 02:24:30
array of objects, what is hard to understand ?
2008-12-28 02:36:23
Yes, you put an object as a variable, not difficult to understand
2008-12-28 02:47:12
the parent function has two references, respectively, to only two sub-objects
2008-12-28 03:03:36
right, an array of objects issue. Not previously noticed, long knowledge
2008-12-28 03:19:26
abstract class can declare a variable, but it points to an object must be real
2008-12-28 03:30:39
me why you
2008-12-28 03:41:22
Thank you for reminding ah
upstairs now seems to have understood the meaning of the
Person [] people = new Person [2];
int [] a = new int [2];
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
through so I understand to be a contrast above that the meaning of a word

I could understand the role of the new keyword wrong

2008-12-28 03:54:22
Oh, interesting
2008-12-28 03:56:49
hehe, you yi si
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.