Post
Kotlin
Explain about static variable in kotlin and how to declare it in kotlin?
Posted on 28th March 2024
Static variables are independent of objects. They are not associated with the object but are associated with the class. We can create numerous objects by using a single static member.
Declaring the static variable:
Class stat
{
Static intc;
stat()
{
C++;
}
Static voidgetc()
{
system.out.println(“number of objects=”+c);
}
Public class Exstat
{
Public static void main(String []a)
{
new stat();
new stat();
stat.getcount();
}
}
STILL GOT QUERIES?