It was quite a long time since I was working on something in Java, and I really have very limited experience in creating anything with it at all, for the most part I write at higher levels of these languages, scripting languages and sorting.
I suppose I don't understand the concept of assigning default values to class members.
// parent public class A { protected int value = 0; public void print() { System.out.println(value); } } // child class public class B extends A { int value = 1; }
To save it, instantiating B and calling print () prints the original value "value" set to A.
I guess it’s probably not some kind of common identifier for a “variable with the name“ value ”belonging to this object,“ a certain function on A has a completely different context for “value” than B. does.
What other method exists for organizing common variations of a certain class, but creating a child of a specified class? Some kind of factory object? Interfaces do not seem to be the answer, because then I need to redefine all aspects of this class, so I won nothing.
Any help would be greatly appreciated, thanks.
source share