In PHP:
PHP Code:
class Customer
{
var $firstName;
var $custId;
function setFirstName($firstName)
{
$this->firstName = firstName;
}
function getFirstName()
{
return $this->firstName;
}
function setCustId($custId)
{
$this->custId = custId;
}
function getCustId()
{
return $this->custId;
}
function incrementID()
{
$this->custId++;
}
}
If I understand correctly (I should know this since I know bits of C#.NET), in Java, you cannot do this as firstName is a private variable:
Code:
Customer jane=new Customer();
jane.setFirstName("Jane");
jane.setCustId(5);
System.out.println(jane.firstName); //you have to do System.out.println(jane.getFirstName()), right?
In PHP (at least in PHP4), you can go right ahead and do:
PHP Code:
$jane=new Customer();
$jane->setFirstName('Jane');
$jane->setCustId(5);
echo $jane->firstName;
In fact, there's really no need for set/get functions since the vars are public:
PHP Code:
$jane=new Customer();
$jane->firstName='Jane';
$jane->custId=5;
echo $jane->firstName;
Oh, and I apologize for my pretending to know anything about Java. As I said, I know bits of C#.NET, but I have no idea how Java writes a line. (I think I saw System.out.println in the Java forum once.
)
Bookmarks