Home »
Kotlin »
Kotlin programs »
Kotlin class and object programs
Kotlin program | Example of Various Visibility Modifiers on Package Level
Kotlin | Example of Various Visibility Modifiers: Here, we are implementing a Kotlin program to demonstrate the example of Example of various visibility modifiers on package level.
Submitted by IncludeHelp, on June 13, 2020
Various Visibility Modifiers on Package Level
Program to demonstrate the example of Example of various visibility modifiers on package level in Kotlin
package com.includehelp
// Public by default, visible to everywhere
fun fun1(){
// local variable can not have visibility
var a=5
println("Inside Fun1 $a")
}
// private , visible inside Containing file
// VisibilityModifiersInsidePackages.kt
private fun fun2(){
println("Inside Fun2")
}
// internal , visible inside same module
internal fun fun3(){
println("Inside Fun3")
}
// public by default visible everywhere
var name="IncludeHelp"
// by default public, visible every where
class MyClass
// Main function, Entry point of program
fun main(){
// call function
fun1()
// call function
fun2()
// call function
fun3()
//Access variable
println("Name : $name")
}
Output:
Inside Fun1 5
Inside Fun2
Inside Fun3
Name : IncludeHelp