Age gender pgender namepname substring0 pnamelength

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: blic Person() {age=0; name=" "; gender=' ';} public Person(String na, int ag, char gen) {setAge(ag); setName(na); setGender(gen); } public Person(Person pr) { setPerson(pr);} public void setPerson(Person p) { age=p.age; gender =p.gender; name=p.name. substring(0, p.name.length()); } public void setAge (int a) {age=a;} public void setGender (char g) {gender=g;} public void setName(String na) {name=na.substring(0, na.length());} public int getAge(){return age;} public char getGender () {return gender;} public String getName () { return name;} } Page 13 11/2/2008 Creating an Object Array - 1 Code A A Person[ ] person; person = new Person[20]; person[0] = new Person( ); Only the name person is Only the name person is declared, no array is declared, no array is allocated yet. allocated yet. person State of Memory After A is executed A Page 14 11/2/2008 Creating an Object Array - 2 Code Person[ ] B B person; person = new Person[20]; person[0] = new Person( ); Now the array for storing Now the array for storing 20 Person objects is 20 Person objects is created, but the Person created, but the Person objects themselves are objects themselves are not yet created. not yet created. person 0 1 2 3 4 16 17 18 19 State of Memory After B is executed B Page 15 11/2/2008 Creating an Object Array - 3 Code Person[ ] person; person = new Person[20]; C C person[0] = new Person( ); One Person object is One Person object is created and the reference created and the reference to this object is placed in to this object is placed in position 0. position 0. person 0 State of Memory 1 2 3 4 16 17 18 19 Person After C is executed C Page 16 11/2/2008 Person Array Proc...
View Full Document

This document was uploaded on 03/03/2014.

Ask a homework question - tutors are online