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";
                    }                    
                }
                System.out.println(s);
        }
    }        
Explanation
Anonimous class can't extend String because class String is declared as final.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback