Что можно сказать о следующей программе?

public class String {
    static String[][]String = {{"String"}};       // 1

    static {
        System.out.println(String.class);         // 2
    }

    public static void main(String[] args) {      // 3
        System.out.println(String.class);         // 4
    }
}
Explanation
In this code declaration of class String hides java.lang.String class. So String refers to defined class and no longer to java.lang.String class. Because of this an error will occur in line 1 -java.lang.String type is cannot be cast to the String type

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes