Sail E0 Webinar
Question


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);
}
}
Options:
A .  h
B .  e
C .  l
D .  o
Answer: Option B

"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 ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers