Class reference

I am working on an assignment but I got stuck in a step, I basically have 2 classes and 1 interface, class1 contains 2 constructors and 2 methods, class2 implements the interface everything is working fine however I was told to create a reference to class1 in class2, I have been searching around but I am having trouble finding information, can someone point me to the right direction of a document where I can find information on what a reference to a class is and how to add it, I have found reference to objects but not to classes

All Classes are Objects.

A reference to a Class is created when one instantiates a Class.

In Class2:

Class1 referenceToClass1 = new Class1();

Thank you for the clarification!

Here is an example of what you are asking in regards to One class referencing another.


package com.sitepoint.forums.users;

public class Person {

private String FirstName;
private String LastName;

}


public class User {

private Person person = new Person();
private String username;
private String password;

public User(Person person){

this.person = person;

}


}

If you were to get this person from a Session Variable User class might look something like


public class User {

private Person person = new Person();
private String username;
private String password;

public User(HttpServletRequest request) {

HttpSession thisPerson = request.getSession(false);
this.person = (Person) thisPerson.getAttribute("userInfo");

}

In the first example you are passing a Person object into the User’s constructor. You could directly assign it to the object inside or you ‘could’ call the setter method inside the User constructor for the private Person object.

If you were doing a JSP based website you could grab a Person object out of the Session (This would probably be handled inside a controller though so just look at it for reference since you probable don’t want to tie your object to having a Servlet jar dependency being provided in your project.)

Anyways, you’d get the session then grab the item out of the session and cast it into the type of Object you want. HashMap’s work in a similar way if your map is a generic Object and you pass in a specific Object type.