<span style= "FONT-SIZE:18PX;" >import java.util.*;class j{public static final int count = 011;} public class Seventyfirst extends j{public static final int count = 022; public static void Main (string[] args) { System.out.println (count);} } </span>
Results: 18
<span style= "FONT-SIZE:18PX;" >import java.util.*;class j{public static final int count = 011; Public final int Fun () { return count; }} public class Seventyfirst extends j{public static final int count = 022; public static void Main (string[] args) { System.out.println (count); System.out.println (New Seventyfirst (). Fun ()); } /*public final int Fun () { return count; } */}</span>
If you don't comment out the fun
<span style= "FONT-SIZE:18PX;" >SEVENTYFIRST.JAVA:14: Error: Fun in Seventyfirst () cannot overwrite fun in J () public final int fun () { ^ overridden method is Final1 error </span>
After commenting out
Results:
18
9
See the difference, right?
Final has a different effect on methods and properties in terms of inheritance.
Methods cannot be overridden or hidden when a method is final decorated
When a property is final decorated, the method can be hidden.
As you can see in the property hide , when a property is hidden and can be accessed through super in a subclass, there is a way to provide a method that provides a final type of Get method in the parent class to return the hidden property
The final Java doubts