Private access modifier (private)

Methods, variables, constructors, and structures that are declared private can only be accessed within the declaring class. This is with the exception of private top-level functions and properties that are visible to all members of the same file. Private variables within a class can be accessed from outside the class be declaring getter and setter methods that permit access. Defining setter and getter methods in Java is shown in the following code:

public class Person {  Person(String fullName, int age) {    this.fullName = fullName;    this.age = age;  }  private String fullName;  private int age;  public String getFullName() {    return fullName;  }  public int getAge() {    return age;  }}

In Kotlin, setter and getter creation ...

Get Kotlin Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.