Post

KotlinKotlin

J
James ROBERT

Posted on 27th February 2024|111 views

0
votes

Kotlin Static Variable

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

Answers
P
Harshel Mike

Posted on 27th February 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();

}

}

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