Created
June 9, 2023 07:40
-
-
Save kalaiselvan369/6b109a2674701772a1d509a7228d93f3 to your computer and use it in GitHub Desktop.
Public Modifier usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val recipient = User() | |
recipient.chat( | |
"Hello, ${recipient.displayName} Greetings for the day! Black Friday Sale is nearing" | |
) | |
// marketing person can only send promotion messages to the user. | |
// users confendential information such username, password are not visible outside the class. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
private var userName: String? = null // not accessible outside the class | |
private var password: String? = null // not accessible outside the class | |
val displayName: String = "Joey" // accessible outside the class | |
private val messages = mutableListOf<String>() | |
private fun resetPassword() { | |
} | |
fun chat(message: String) { | |
messages.add(message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment