logo-MindMajix
PostKotlinKotlin
J
James ROBERT

Posted on 26th July 2024|126 views

0
votes

Kotlin Static Variable

Explain about static variable in kotlin and how to declare it in kotlin?

1 answers
Answers
P
Harshel Mike

Posted on 26th July 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();

}

}

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number