[SalesForce] Accessing PageReference method from different class

I'm a newbie to salesforce.
I have 2 Apex class as follows:

public class A {

B bb;

public PageReference save() {

bb = new B();
return bb.pay();
}

}

public class B {

public PageReference pay(){

}

}

I would like to return the PageReference method pay() at class B on class A. Is that possible? Or Are there any other way for me to call the pay() method from class A? Cuz right now, when I call the method from save() it won't redirect me to pay()

Thanks to the kind hearted soul!

Best Answer

I'm not sure where you're going with this because the code you posted is pretty vague. Maybe you could make this a static method if you are only calling the PageReference exactly after you're instantiating the object. Here's a way to expedite the call of an instance method. This one goes to a new opportunity.

public class A
{
  public PageReference save()
  {
    return (new B()).pay();
  }
}

public class B
{
  public PageReference pay()
  {
    PageReference pageRef = new PageReference('/006/e');
    pageRef.setRedirect(true);
    return pageRef;
  }
}