I noticed I can do:
public class Message {
public static final int MIN_BYTES = 5;
}
...and set this class as parent of another and set the same constant with another value like:
public class Ack extends Message {
public static final int MIN_BYTES = 1;
}
Since compiler does not complaing, this lead me to the questions above:
Thanks!
Ack.MIN_BYTES
and Message.MIN_BYTES
have no relationship to each other.a.MIN_VALUE
depends on the static type of a
-- if you write Message a = new Ack()
, then a.MIN_VALUE
will give you Message.MIN_BYTES = 5
. If you write Ack a = new Ack()
, then a.MIN_VALUE
will give you Ack.MIN_BYTES = 1
.The second does not overwrite the first. It just hides it within Ack
. ALL class members declared public static final
can be accessed using [fullpackagename].[classname].[variablename]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With