June 5, 2002 - Writing a Classic Base Class
June 5, 2002 Writing a Classic Base Class Tips: June 2002
Yehuda Shiran, Ph.D.
|
Employee
class, which we can use as a base class for other classes, such as the
Manager
class (not shown here):
class Employee{
var name : String;
var address : String;
function Employee(empName : String){
this.name = empName;
}
function printMailingLabel() {
print(name);
print(address);
}
}
Let's create an instance of the Employee
class, and set its name
and address
:
var Bob : Employee = new Employee("Bob Smith");
Bob.address = "2010 University Avenue, Palo Alto, CA 94301";
The command Bob.printMailingLabel()
will yield the following output:
Bob Smith
2010 University Avenue, Palo Alto, CA 94301
To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.