Why can't we override System class methods in Java


Below is a link to the source code of the system class of Java's LANG package. Which I have taken from the internet.

http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/cf44386c8fe3/src/share/classes/java/lang/System.java

There are two main points

1. The system class is a final class. It cannot be extended. If we are declaring someone as a finalist then it means that it will not be expanded further. You are in a situation from which you should not move forward.












2. Perhaps you never tried to look at the System class. If you would have seen by opening the system class, then you would know that all its methods are static.

























Now you know about the static method, then you will also know that these methods will be loaded with the class. Static methods  are common to all object of same class.

If a method is static, it cannot be overridden. I am assuming here that you know to override a method of  class,
So Can't override method of System class simply because of final and static

Comments

Popular posts from this blog

Predicate The Functional interface in java

NodeJS vs Java

JPA mappedBy and JoinColumn