0 votes
112 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 127 views
asked May 15, 2022 in C program by Doubtly (98.9k points)
0 votes
1 answer 202 views
0 votes
1 answer 116 views
0 votes
1 answer 168 views
0 votes
1 answer 118 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

535 users

...