Scala | Controlling visibility of constructor fields Last Updated : 17 Sep, 2019 Comments Improve Suggest changes Like Article Like Report The visibility of the Constructor Fields in the Scala language is maintained and controlled by the way of declaration. These can be declared in the below forms: Declared as val Declared as var Declared without var and val Add Private to the fields. We'll now see all the above methods with more detail and help of some examples: When field is declared as var If the field is declared as var then Scala language automatically generates both Getter and Setter modes for that particular field. This means that the value of the field can always be changed. Example 1: When field is declared as val If the field is declared as val then value of the fields assigned in the start cannot be changed and permanently remains set. In this case Scala only allows getter method. Example 2: When field is declared without val and var If the field is declared without var and val then visibility of the field is very restricted and Scala does not permit setter and getter methods. the visibility of the field becomes restricted. Example 3: Adding the keyword Private We can also mention the keyword "private" in addition with the var and val modes. This makes the field accessibility in the same way as we do in C++. This stops the methods getter and setter and the field is normally accessed using the member functions of the class. Example 4: Thus the above-discussed cases are the different kinds of visibility modes that are possible in the Scala Constructor Class. Comment More infoAdvertise with us Next Article Scala | Controlling visibility of constructor fields S ShikharMathur1 Follow Improve Article Tags : Scala Scala Scala-OOPS Scala-Constructor Similar Reads Controlling the Visibility of Class and Interface in Java Maintenance is one of the important aspects of software development, and experience has shown that software that maintains its component's visibility low is more maintainable than one that exposes its component more. You're not going to know it upfront, but when redesigning the application, you're g 5 min read Controlling Method Scope In Scala As the name suggests Access Modifiers in scala helps to restrict the scope of a class, variable, method or data member. Controlling Method Scope In Scala helps to restrict the scope of method or data member. There are five types of controlling method scope in Scala: Public Scope Private Scope Protec 5 min read Scala | Primary Constructor Constructors are used to initializing the objectâs state. Like methods, a constructor also contains a collection of statements(i.e. instructions). statements are executed at the time of object creation. When our Scala program contains only one constructor than that constructor is called a primary co 4 min read Scala Constructors Constructors are used to initializing the objectâs state. Like methods, a constructor also contains a collection of statements(i.e. instructions) that are executed at the time of Object creation. Scala supports two types of constructors: Primary Constructor When our Scala program contains only one c 4 min read Rust - Struct Visibility In Rust, there is a concept of Struct Visibility. Generally, the items present in the module have visibility that is private by nature but we can override the private items by usage of the public ('pub') modifier. Public items of the module are accessed outside the module scope and the visibility in 3 min read Like