Java · Question 20 · Easy

What will be the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        System.out.println("Mumbai".substring(1, 4));
    }
}
  1. mba
  2. umb
  3. umba
  4. Mumb
Answer and explanation

Answer: B. umb

Explanation: substring(1, 4) returns the characters from index 1 up to but not including index 4, which are u, m and b.

Previous: Which access modifier makes a class member accessible only within the class in… · Next: Which of the following statements about interfaces is true in Java 8 and later?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge