Java Reference
In-Depth Information
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFullName() {
return firstName + " " + lastName;
}
}
Consider the code in Listing 6-5. It extends the Person class and override the
getFullName() method.
Listing 6-5. Using the Java.super() Method to Access Superclass Methods
// supermethod.js
var Person = Java.type("com.jdojo.script.Person");
var PersonExtender = Java.extend(Person);
// Extend the Person class and override the getFullName() method
var john = new PersonExtender("John", "Jacobs") {
getFullName: function () {
// You can use the variable john here that is declared outside.
var _super_ = Java.super(john);
var fullName = _super_.getFullName();
return fullName.toUpperCase();
}
}
// Get john's full name using the extended class implementation
var johnFullName = john.getFullName() ;
// Get the reference of john's super
var johnSuper = Java.super(john);
Search WWH ::




Custom Search