|
-
Feb 5th, 2012, 06:06 PM
#1
Thread Starter
Member
Use classes inside of other classes
Hello forumers ! I've got a problem.
The "exercice":
1 class called "Person"
name, last name and age of every person, with their getters and setters.
1 class called "Codes"
int code, String rank. Here I will put the codes for every person.
1 main class called "Simulator"
Instanciate new persons and show system.out.print messages.
What I need is to instanciate "Codes" inside of "Person" (Like that: private Codes code and use it in the Simulator. For example:
CLASS PERSON
private String name = "";
private int age = 0;
private String lastname = "";
private Codes code;
[... getters ... setters ...]
CLASS CODES
private int code = 0;
public void setCode(int c){
code = c;
}
public int getCode(){
return code;
}
CLASS SIMULATOR MAIN
person p1 = new person();
p1.setName("John");
p1.setLastName("Petrucci");
p1.setEdad(43);
p1.Codes.code ?????
System.out.println("Name: "+p1.getName()+" "+p1.getLastName()+" and the age is: "+p1.getAge());
System.out.println("The code is: "p1.Codes.code?????" );
Don't really know how to use classes inside another classes that aren't the main class.
Please help !!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|