top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can final variables be made static in Java?

0 votes
404 views

Can final variables be made static in Java, please explain with example?

posted Jan 25, 2016 by Abhay Dubey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Yes.

Doing so allows you to refer to the constant through its class name rather than through an object.

For example, if the constants in ErrorMsg were modified by static, then the println( ) statements in main( ) could look like this:

System.out.println(err.getErrorMsg(ErrorMsg.OUTERR));
System.out.println(err.getErrorMsg(ErrorMsg.DISKERR));
answer Jan 25, 2016 by Danial Rotwaski
Similar Questions
0 votes

By making private constructor, we can avoid instantiating class from anywhere outside and by making class final, no other class can extend it. Why is it necessary for Util class to have private constructor and final class ?

+4 votes

I was wondering if final and static variables are same. I know they are different, but what is the purpose of final? When should we use final and when to use static.

Thanks in advance.

+1 vote

how can change final data and methods in java?

...