ICSE Class 10 Computer Applications
Question 15 of 30
Solved Sample Paper 2 — Question 15
Back to all questions 15
Question Question 1(xv)
What will be the output of following code?
String c = "Hello i love java";
boolean var;
var = c.startsWith("hello");
System.out.println(var);- true
- false
- 0
- 1
false
Reason — An important point to note in this code is that startsWith() method in Java is case-sensitive, meaning it will differentiate between uppercase and lowercase characters. In this case, the prefix "hello" starts with a lowercase 'h', but the string in c starts with an uppercase 'H'. Since the cases don't match, the startsWith() method will return false. So var will be assigned false and given as output.