This is how assignment of classes is done in the S3 system of method dispatch. It's not really OOP as Java users understand it. The proto
package provides a framework that more closely resembles Java style OOP. The S4 system of method dispatch provided multi-argument signature matching and a more discipline approach... that most R-users cannot understand.
newItem <- "bbb"
class(newItem) <- "newClass"
print(newItem)
#[1] "bbb"
#attr(,"class")
#[1] "newClass"
print.newClass <- function(n) cat("this is of the newClass", n)
print(newItem)
#this is of the newClass bbb
otherItem <- "xxxx"
inherits(otherItem, "newClass")
#[1] FALSE
class(otherItem) <- c( class(otherItem), "newClass")
print(otherItem)
#this is of the newClass xxxx
When you talk about "classes" being in a "different file", then you probably need to study package construction and the care and feeding of NAMESPACEs. You are able to attach packages as well as load via namespaces. R functions are perhaps somewhat similar to Java classes (in a rather loose use of the English language, but not either Java or R) but in R, the term 'class' refers to an attribute of an object which is used to dispatch functions.