Posted on 9th September 2024|126 views
Explain about static variable in kotlin and how to declare it in kotlin?
Posted on 9th September 2024| views
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();
}
}