What will be the output of the following Java code?

class output 
   {
       public static void main(String args[])
       { 
          String c = "Hello i love java";
          boolean var;
          var = c.startsWith("hello");
          System.out.println(var);
       }
   }

a) true
b) false
c) 0
d) 1

1 thought on “What will be the output of the following Java code?”

  1. b
    Explanation: startsWith() method is case sensitive “hello” and “Hello” are treated differently, hence false is stored in var.
    Output:
    $ javac output.java
    $ java output
    false

Leave a Comment