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);
  1. true
  2. false
  3. 0
  4. 1
Answer

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.

Get the Bright Tutorials app Stuck on a question? Ask Bright Buddy — your AI tutor — for step-by-step help in the app.