One of my colleagues read this in a book of Data Structures, that in Java if a class is made as final(assuming that its not going to be inherited any further), then it increases the run time performance.
Can someone pls explain how does this happen? How is the bytecode of a final class is different from that of a normal class and in what way is its behaviour different at run time?
hi inheritance involve key issue of polymorphism which is related to latebinding or dynamic binding.
if a class is final it cannot be inherited. its all methods are also final that means methods cannot be overridden. so no need of dynamic binding. only static binding and dynamic binding has more overheads than static binding. hence if a class or a method is final only static binding is involved (less overheads at runtime). thus improved performance is achieved.