Classes in Scala are similar to classes in Java. They are blueprints describing an object providing fields and methods. One difference is that classes can have parameters. Examine how a sample class that represents a computer can be achieved.
- [Narrator] Classes in Scala are similar…to classes in Java.…They're blueprints that describe an object,…providing fields and methods.…One difference is that classes can have parameters.…Let's look at a sample class that represents a computer.…Since I'm using the worksheet option inside…the Scala IDE, I do have my our object called computer…and my print line that says welcome to…the Scala worksheet, but next is where I define my class.…My class is called Computer with the capital C…and it has three values; it has the make, the model…and the amount of ram; I wanted to make sure that I overrode…my toString method, so that I could print out…the meaningful information about my computer.…
So, you'll notice, you have to use the keyword override…and then I have def toString which returns a string;…is equal to; and then I put square brackets around…and I put the make plus, comma, then the model…plus, a comma and then the ram and then I use the backslash…and escape sequence to give me a new line after it…prints each of my make, model and ram for my computers.…
- Installing Scala
- Integrating with IDEs
- Creating variables
- Using special functions
- Basic types and operations
- Tuples, sets, maps, arrays, and lists
- Classes, fields, and methods
- Singleton objects
Skill Level Intermediate
1. Why Scala?
2. Scala Basics
3. More Scala Basics
4. Objects with Scala
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.