This week's book giveaways are in the Cloud and AI/ML forums. We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line! See this thread and this one for details.
I thought that once a field was declared static, then there was only one copy of that field. I thought the same went for methods. I wanted to prove that to myself, and the results weren't what I expected:
I had thought that field 'a' would be re-set to 2 in class TrigClass, and that it would be 2, even when called from within class Class, if the call came after it was re-set to 2. Also, I thought method swing() in class Class would be overwritten by the swing() in TrigClass, and there would be only one method (which would print "swing in TrigClass"). In main(), apparently, both fields (a in TrigClass and a in Class) and both methods (swing() in each class) exist independently. If that's the case, what's the point of static? What is unique about a field/method when they're declared static?
static simply means belonging to a class, rather than to an object. So, static method in class A, belongs to class A. And you can call it, without needing an instance of class A. So, that's the point of having static members.
inheritance is a relationship between classes, where only non-static methods/fields participate; static methods/fields have no bearing on that.