On 6/30/2014 4:35 PM, Guillermo Lopez wrote:
If the Student class has an instance variable whose type is
StudentRecord class and this variable name is sudentRecord, How do
you createe one object type studentRecord ?
The object you will created is Student type, then how you get access
to studentRecord class?
What I expect is rather simple - this is not a trick question :-).
The following is what I expect in the main() method.
StudentRecord annaRecord =new StudentRecord();
annaRecord.setName("Anna");
Student annaStudent = new Student();
annaStudent.setStudentRecord(annaRecord);
annaStudent.setStudentId(1);
Student.increaseStudentCount();
System.out.println("id = " + annaStudent.getStudentId() + "name
= "
+ annaStudent.getStudentRecord().getName());
The following is the Student class
public class Student {
private StudentRecord studentRecord;
private Integer studentId;
// Declare static variables.
private static int studentCount = 0; // Declare static variables.
/**
* @return the studentRecord
*/
public StudentRecord getStudentRecord() {
return studentRecord;
}
/**
* @param studentRecord the studentRecord to set
*/
public void setStudentRecord(StudentRecord studentRecord) {
this.studentRecord = studentRecord;
}
/**
* Returns the number of instances of StudentRecords
*/
public static int getStudentCount(){
return studentCount;
}
/**
* Returns the number of instances of StudentRecords
*/
public static void increaseStudentCount(){
studentCount++;
}
/**
* @return the studentId
*/
public Integer getStudentId() {
return studentId;
}
/**
* @param studentId the studentId to set
*/
public void setStudentId(Integer studentId) {
this.studentId = studentId;
}
}
Kind regards,
Guillermo.
--
You received this message because you are subscribed to the Google
Groups "JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/d/optout.
--
-------------------------------------------------------------------
Sang Shin, [email protected]
Founder and Chief Instructor of JPassion.com (JavaPassion.com)
http://www.linkedin.com/in/javapassion (Linkedin)
http://twitter.com/javapassion (Tweeter)
Life is worth living... with Passion!
Practically Free 3 to 5 days Live, Hands-on, Online Codecamps on
Java, HTML5, Ruby/Rails, Grails, JavaScript/jQuery, Spring, Android
http://jpassion.com/codecamps
----------------------------------------------------------------------
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/d/optout.