The following question: Consider the following piece of code and select the correct statements. 1. Object o = new String("abcd"); 2. String s = o; 3. System.out.println(s); 4. System.out.println(o); This obviously won't compile because of the downcast in line 2. However, this answer was supposedly incorrect: Change line 1 to String o = new String("abcd"). Did I just lose my mind here?
posted 15 years ago
Hi Gregory, By changing the first line to String o = new String("abcd"); the downcast compiler error is effectively removed. Therefore, the code will compile with no errors.