Which code segments should you use?

You are creating a class named Consultant that mustinherit from the Employee class.
The Consultant class must modify the inherited PayEmployee method.
The Employee class is defined as follows.
function Employee() {}
Employee.prototype.PayEmployee = function ( ){
alert(‘Hi there!’);
}
Future instances of Consultant must be created withthe overridden method.
You need to write the code to implement the Consultant class.
Which code segments should you use? (Each correct answer presents part of the solution. Choose two.)

You are creating a class named Consultant that mustinherit from the Employee class.
The Consultant class must modify the inherited PayEmployee method.
The Employee class is defined as follows.
function Employee() {}
Employee.prototype.PayEmployee = function ( ){
alert(‘Hi there!’);
}
Future instances of Consultant must be created withthe overridden method.
You need to write the code to implement the Consultant class.
Which code segments should you use? (Each correct answer presents part of the solution. Choose two.)

A.
Consultant.PayEmployee = function ()
{
alert(‘Pay Consulant’);
}

B.
Consultant.prototype.PayEmployee = function ()
{
alert(‘Pay Consultant’);
}

C.
function Consultant () {
Employee.call(this);
}
Consultant.prototype = new Employee();
Consultant.prototype.constructor = Consultant;

D.
function Consultant() {
Employee.call(this);
}
Consultant.prototype.constructor = Consultant.create;

Explanation:
You can assign a different thisobject when calling an existing function. thisrefers to the current object, the
calling object.
With call, you can write a method once and then inherit it in another object, without having to rewrite the
method for the new object.



Leave a Reply 0

Your email address will not be published. Required fields are marked *