Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between final, const and static variables in java

What is the difference between final, const and static variables in java with code example please `

like image 576
Nemo Avatar asked May 18 '26 11:05

Nemo


1 Answers

class X
{
  static int s; // can be accessed as X.s without object
  final int f = 7; // can't be assigned a different value
  const int c; // doesn't compile
}
like image 79
Atsby Avatar answered May 21 '26 01:05

Atsby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!