Now that we know something about Scala’s built-in type, let’s look at its
objects. Objects in Scala are created in classes. Classes are like the skeleton to
objects. As a companion to classes, singleton objects can be declared using
the keyword ‘objects’. When a class and an object share the same name, they
are companions to each other. In addition, they are able share each other’s
member, including private members. Objects can be declared as ‘Traits’ in
Scala as an alternative. ‘Traits’ is very similar to Java’s interface, however ‘traits’
can be implements solely.
Different from Java’s interface, traits can be ‘mix-in’ with other traits and classes when constructing methods.
Different from Java’s interface, traits can be ‘mix-in’ with other traits and classes when constructing methods.
No comments:
Post a Comment