Hi guys,
I am confused on how can I access a same class reference object , that is created in class ReadInoiceFile, and be accessed in ReadErrorFile.
To be more specific:
I have a class called Transaction
And then I have a class called ReadInvoiceFile.
And finally I have a class called ReadErrorFile.
So if I create a reference object of Transaction in ReadInvoiceFile and use the mutator method setOrderNumber to set a value of a variable called OrderNumber, how can I get access to that value in class ReadErrorFile.
Because if I create a reference object of Transacton in ReadErrorFile and try accessing OrderNumber I get a new copy which initially will be null.
Here is code snippet. I hope my question makes sense and thanks for any help.
public class Transaction
{
private String InvoiceNumber ;
private String OrderNumber;
public Transaction()
{
InvoiceNumber = " ";
OrderNumber = " ";
}
public void setInvoiceNumber(String InvoiceNo)
{
this.InvoiceNumber = InvoiceNo;
}
public void setOrdrNumber(String OrderNo)
{
this.OrderNumber = OrderNo;
}
public String getInvoiceNumber()
{
return InvoiceNumber;
}
public String getOrderNumber()
{
return OrderNumber;
}
public class ReadInvoiceFile
{
Transaction transaction = new Transaction();
public void ReadInput()
{
transaction.setOrderNumber("123AF");
}
}
public class ReadErrorFile
{
//this would create complete new object
Transaction transaction = new Transaction();
public void getResults()
{
//this would print out null
System.out.println(transaction.getOrderNumber());
}
}
}