Visibility variable OOP in kotlin


#1

Hello
Is my friends good?
I was learning object-oriented (teaching with Java language) and I was doing Kotlin
In the example that I sent to the attachment.
I have two variable in two class named “chargerType” and their visibility is private
How can i change the visibility of two variable named “chargerType” to Public in the example?
When I’m doing, I’m taking some error.

MainActivity.kt Code :
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val mobile: SmartPhone = SmartPhone()
    mobile.turnOn()
    Log.i("LOG", "Is turned On :" + mobile.isTurnedOn())
    Log.i("LOG", "Charger Type :" + mobile.getChargerType())
    mobile.turnOff()
    Log.i("LOG", "Charger Type :" + mobile.getChargerType())
}

}

A Super class is :
public open class DigitalDevice {
private var chargerType: String = “AC”

private var isTurnedOn: Boolean = false
public open fun turnOn() {
    Log.i("LOG", "Digital Device Turned On")
    isTurnedOn = true
    boot()
}

public open fun turnOff() {
    shutdown()
    isTurnedOn = false
    Log.i("LOG", "Digital Device Turned Off")
}

public open fun isTurnedOn(): Boolean {
    return isTurnedOn
}

public open fun getChargerType(): String? {
    if (isTurnedOn) {
        return chargerType
    } else {
        return null
    }
}

private fun boot() {
    Log.i("LOG", "Device is Booting....")
    Log.i("LOG", "Some action in Boot")
    Log.i("LOG", "Device Booted")
}

private fun shutdown() {
    Log.i("LOG", "Device id Shutting down...")
    Log.i("LOG", "Some action in shutdown")
    Log.i("LOG", "Device shutdown")

}

}

A Sub class :
public class SmartPhone : DigitalDevice() {

private var chargerType: String? = "USB"

@Override
override fun getChargerType(): String {
    val type: String? = super.getChargerType()
    if (type == null) {
        return "SmartPhone is turned off"
    }
    return type
}

}