0 votes
142 views
in JAVA by (98.9k points)
edited

What is the purpose of static methods and variables?

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

The methods or variables defined as static are shared among all the objects of the class. The static is the part of the class and not of the object. The static variables are stored in the class area, and we do not need to create the object to access such variables. Therefore, static is used in the case, where we need to define variables or methods which are common to all the objects of the class.

For example, In the class simulating the collection of the students in a college, the name of the college is the common attribute to all the students. Therefore, the college name will be defined as static.

Related questions

0 votes
1 answer 151 views
asked May 15, 2022 in C program by Doubtly (98.9k points)
0 votes
1 answer 224 views
0 votes
1 answer 136 views
0 votes
1 answer 184 views
0 votes
1 answer 186 views
asked Aug 9, 2022 in JAVA by Doubtly (98.9k points)

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...