Examveda
Examveda

What will be the output of the following program?
public class Test{
        public static void main(String args[]){
		String str1 = "one";
		String str2 = "two";
		System.out.println(str1.concat(str2));
        }
}

A. one

B. two

C. onetwo

D. twoone

E. None of these

Answer: Option C

Solution(By Examveda Team)

Concat() method appends one String to the end of another. The method returns a String with the value of the String passed into the method appended to the end of the String which is used to invoke this method.


This Question Belongs to Java Program >> Strings

Join The Discussion

Comments ( 2 )

  1. Saurabh Singh
    Saurabh Singh :
    5 years ago

    the ans given is wrong beacuse str1 and str2 both are in string constant pool and refer diffrent object. so according to the question there is no change int str1 and output will be str1. If str1=str1.concat(str2) was given then the new object of str1 is formed and output will be onetwo.

  2. Sandhya Yadav
    Sandhya Yadav :
    7 years ago

    Since Str1 =one , Str2 = two..both are allocated in constant pool of string pool....if they concate then where do they store with what reference str1 or str2?

Related Questions on Strings