Question
class String_demo {
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
System.out.println(s);
}
}
What is the output of this program?
class String_demo {
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
System.out.println(s);
}
}
Answer: Option B
Was this answer helpful ?
ascii is an array of integers which contains ascii codes of Characters A, B, C, D. String(ascii, 1, 3)
is an constructor which initializes s with Characters corresponding to ascii codes stored in array ascii,
starting position being given by 1 & ending position by 3, Thus s stores BCD.
output:
$ javac String_demo.java
$ java String_demo
BCD
Was this answer helpful ?
More Questions on This Topic :
Question 9.
Which of these is an oncorrect statement?
....
Submit Solution