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 + ".");
}
}
}
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
Join The Discussion
Comments ( 3 )
Related Questions on Strings
In Java, which class is used to represent a sequence of characters as a string?
A. String
B. StringBuilder
C. StringSequence
D. StringArray
What is the correct way to create a new empty String object in Java?
A. String emptyString = "";
B. String emptyString = new String();
C. String emptyString = " ";
D. String emptyString = null;
E. Both A and B
Which of the following methods is used to compare two strings for equality in Java?
A. equals()
B. compareTo()
C. equalsIgnoreCase()
D. compare()
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.
can someone please explain this ??
??