Question
class output {
public static void main(String args[])
{
char ch;
ch = "hello".charAt(1);
System.out.println(ch);
}
}
What is the output of this program?
class output {
public static void main(String args[])
{
char ch;
ch = "hello".charAt(1);
System.out.println(ch);
}
}
Answer: Option B
Was this answer helpful ?
"hello" is a String literal, method charAt() returns the character specified at the index position.
Character at index position 1 is e of hello, hence ch contains e.
output:
$ javac output.java
$ java output
e
Was this answer helpful ?
Submit Solution