Hello,
 
###  I created two classes "A" and "B". "A" is the superclass of "B".
 
setClass("A", representation(s1="numeric"),prototype=prototype(s1=8))
setClass("B",contains="A",representation(s2="character"),prototype=list(s2="hi"))
myA=new("A")
myB=new("B")
 
####  I created functions for "A" and "B"
 
f1=function(x,...) UseMethod("f")
f.default=function(x,...){
    print("default")
 }
 f.A=function(x,...) {
     print(paste("x@s1=", x@s1, sep=""))
     NextMethod()
 }
 f.B=function(x,...) {
     print(paste("x@s2=", x@s2, sep=""))
     NextMethod()
 }
 
#### when I do
 f1(myB)
## R gave me the result
[1] "x@s2=hi"
[1] "default"
## but I think the result should be 
[1] "x@s2=hi"
[1] "x@s1=8"
[1] "default"
 
## because the the NextMethod() should go to f1.A not directly to f1.default.
could you please tell me where I got wrong understanding?
 
Yu
 

 


      
	[[alternative HTML version deleted]]

