Keywords are the words in a language that are used to represent some predefined actions or some internal process. We use the this keyword when we want to introduce the current object for a class. Then using the dot operator (
.), we can refer to instance variables, methods and constructors by using this keyword. this keyword is also used with auxiliary constructors.
Let’s understand this keyword with some examples.
15 + 12 = 27
In above example, a class addition defined which consist one parameter and in that classs we created a method using this keyword with two parameters i and j. In this method a primary constructor is also invoked (i.e this(i)).
Language name Scala published article 105
As we can see, in above example, an auxiliary constructor defined with this keyword and a primary constructor called using this keyword. instance variables (i.e Lname, Articles)is also referred using dot(.) operator.
- Throw Keyword in Scala
- Scala | yield Keyword
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala short <(x: Short): Boolean
- Scala short <(x: Char): Boolean
- Scala Extractors
- Scala | Partially Applied functions
- Scala String indexOf(String str) method with example
- Scala String contentEquals() method with example
- Scala Keywords
- Scala Int /(x: Int) method with example
- Scala Int /(x: Short) method with example
- Program to print Java Set of characters in Scala
- Scala Map size() method with example
- Scala SortedMap addString() method with a start, a separator and an end with example
- Scala Iterator addString() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala | Functions Call-by-Name
- Program to convert Java list to an iterator in Scala
- Scala Set &() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.