Menu
Topics Index
...
`

My campus


If you need explanation Read this topic

If you need Answer Take test on this topic

My campus
What will be the output of the following program?
public class Campus {
    public static void main(String[] args) {
        String name = "MERIT CAMPUS";
        StringBuffer sb = new StringBuffer(name);
        sb = sb.substring(3);
        System.out.println(sb);
    }
}

A. IT CAMPUS
B. MERIT CAMPUS
C. Compilation Error
D. Runtime Error
Topic: Java substring

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is C,bcoz substring works only with string class

Posted by Raviteja Daggupati    2014-01-23 12:42:16


Ans is A since  substring(3) extracts all characters from index 3 to end of the string buffer sb.

Posted by Soundarya Velugubantla    2014-01-23 12:44:09


ans is C becuase incompatible types   we cannot assign a string to stringbuffer as substring returns string type object

Posted by Akash Kolariya    2014-01-23 12:57:54


Answer is C because substring() Methode is for String class only not StringBuffer class

Posted by Ben Khlifa Fahmi    2014-01-23 13:22:19


c,string cannot be assigned to string buffer

Posted by Ramreddy Srinivas Reddy    2014-01-23 13:35:26


Congratulations Raviteja Daggupati. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-24 04:04:26


© meritcampus 2019

All Rights Reserved.

Open In App