student <- function(n, a, r){
value <- list(name = n, age = a, rno = r)
attr(value, "class") <- student
value
}
print.student <- function(obj){
cat(obj$name, "\n")
cat(obj$age, "\n")
cat(obj$rno, "\n")
}
s <- list(name = "Utkarsh", age = 21, rno = 96,
country = "India")
class(s) <- c("InternationalStudent", "student")
cat("The method print.student() is inherited:\n")
print(s)
print.InternationalStudent <- function(obj){
cat(obj$name, "is from", obj$country, "\n")
}
cat("After overwriting method print.student():\n")
print(s)
cat("Does object 's' is inherited by class 'student' ?\n")
inherits(s, "student")