Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make Subclasses static values be seperate?

I have a issue with static variables in abstract classes because When i extend a class as a subclass it shares the same Variable value as all of the other ones And i wanted to know if there is a way to fix it without making each class seperate but still making the variables seperate.

My code Changes the variable When the subclass constructs But it it keeps the value of the last Subclass that is constructed which is the issue.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Static fields are always shared over all instances of a class, and subclasses, as they belong to the class.

If you want different class instances to have different values of their fields, you need instance variables.

protected, non static variables can be shared and accessed from subclasses

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading