What will be the result of compilation and execution of the following code?
public class TestClass {
    public static void main(String[] args) {
                String s = new String(){
                    public String toString(){
                        return "new method";
Anonimous class can't extend String because class String is declared as final.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback