Examveda
Examveda

What will be the output?
public class Test{
     public static void main(String args[]){
           Object myObj = new String[]{"one", "two", "three"};
           {
          for(String s : (String[])myObj) 
	        System.out.print(s + ".");
         }
     }
}

A. one.two.three.

B. Compilation fails because of an error at line 3

C. Compilation fails because of an error at line 5

D. An exception is thrown at runtime.

E. None of these

Answer: Option A


This Question Belongs to Java Program >> Strings

Join The Discussion

Comments ( 3 )

  1. Yogesh Chaudhari
    Yogesh Chaudhari :
    5 years ago

    Here string array is initialized and assigned to the Object type. And in for each loop
    the object is typecast to string array for printing.

  2. Vasundhra Chib
    Vasundhra Chib :
    6 years ago

    can someone please explain this ??

  3. Rahul Sharma
    Rahul Sharma :
    6 years ago

    ??

Related Questions on Strings