Scala Traits by Code Example

We all might know about Java Interfaces. Traits in Scala are very much similar to Java Interfaces. There is just one exception if we compare traits with interfaces in Java (Java 7 and earlier version) and that is traits can also have methods with implementation. Let’s look from different perspective. In Scala we can treat traits same as classes which doesn’t have constructors with parameters. Continue reading “Scala Traits by Code Example”

Scala Data Types by Code Example

Being a purely object oriented language each and every value in Scala world is an object. Even all of the primitive data types of Scala are the objects. And as I also has mentioned in my earlier post related to Scala Methods, there is no native operator available in Scala. Instead, Scala uses a corresponding method which look like an operator. Continue reading “Scala Data Types by Code Example”

Scala Classes, Objects & Singleton Objects

Previously we have learned about Scala Programming Language, Variable Declaration and Method Declaration. Now we’ll have a closer look at the Scala classes and Objects. We’ll also learn about creating Singleton objects in Scala.

Similar to Java, classes in Scala describes the objects. Classes may contain reference variables, methods as well as constructors. Continue reading “Scala Classes, Objects & Singleton Objects”