Reputation: 1423
Here is what I was asked in interview:
If a new method is added to String class and compiled and put in rt.jar, then will bootstrap class loader load it?
I answered that it will not get loaded but could not tell why.
Please help me with correct answer and explanation of that.
Upvotes: 0
Views: 167
Reputation: 308001
It will be loaded.
And not just that: it need not even be in rt.jar
, if you prepend a jar file to the boot-classpath (see -Xbootclasspath/p:path
), then you can even load java.lang.*
classes from other jar files.
This of course is a way to violate the security of the JVM, but you need pretty deep access (either write-access to rt.jar
or access to the command line parameters of the JVM) and when you have those, you can do a lot more than just replace String.toString()
.
Upvotes: 1