Singleton objects provide a convenient way to group functions that are not members of a class. A singleton is a class with a single instance. A singleton declares a class, such as helloworld, and one instance of that class. Learn more about the Scala sing
- [Narrator] So far, we've seen many instances in our code…where we've created objects using the "object" keyword…rather than the keyword "class".…This type of object actually has a special name.…It's called a singleton.…Singleton objects provide a convenient way…to group functions that aren't members of a class.…Let's start this Scala interactive session…and take a look at how to create a singleton.…I'm going to type "scala" on my command prompt,…and now I'm going to create an object that we're familiar with,…a HelloWorld object that will just print out "Hello World".…
So let's go ahead and get started.…We use the keyword "object".…Any time in Scala,…when you use the keyword "object",…you're actually creating a singleton.…And we'll give it a name, we'll call it "HelloWorld".…Open curly bracket,…then we'll define our main method.…We'll pass in our arguments,…which are type Array,…which is of type String.…And our main method is going to have a print line statement…that says "Hello World".…That's the end of the main method,…
- 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?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.