Log In Register

Units


Java String - Questions and Answers

 

Practice these Java String under Java Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Java String for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Java String of Java Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge Java Programming specifically Java String.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Java String under Java Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Java String topic of Java Programming:

 

1. What is the output of the following println statement? String str1 = "Hellow"; System.out.println(str1.indexOf('t'));

Answer: Option

Explanation:

2. What will be output? String S1 = "S1 ="+ "123"+"456"; String S2 = "S2 ="+(123+456);

Answer: Option A

Explanation:
If a number is quoted in "" then it becomes a string, not a number any more.

3. Determine output: public class Test{ public static void main(String args[]){ String str = null; if(str.length() == 0){ System.out.print("1"); } else if(str == null){ System.out.print("2"); } else{ System.out.print("3"); } } }

Answer: Option D

Explanation:

4. Which of these constructors is used to create an empty String object?

Answer: Option A

Explanation:

5.

How many objects will be created?

String a = new String("TestMirror");
String b = new String("TestMirror");
String c = "TestMirror";
String d = "Testmirror";

Answer: Option B

Explanation:

6.

The output of the following fraction of code is

public class Test{
        public static void main(String args[]){
	        String s1 = new String("Hello");
		String s2 = new String("Hellow");
		System.out.println(s1 = s2);
	}
}

Answer: Option B

Explanation:

7.

What will be the output of the following program code?

public class Test{
      public static void main(String args[]){
            String s = "what";
            StringBuffer sb = new StringBuffer("what");
            System.out.print(sb.equals(s)+","+s.equals(sb));
      }
}

Answer: Option D

Explanation:

8. Which of these method of class String is used to compare two String objects for their equality?

Answer: Option A

Explanation:

9. The output of the following fraction of code is public class Test{ public static void main(String args[]){ String s1 = new String("Hello"); String s2 = new String("Hellow"); System.out.println(s1 = s2); } }

Answer: Option B

Explanation:

10. toString() method is defined in

Answer: Option B

Explanation:

11.

What will be the output of the following program code?

class LogicalCompare{
        public static void main(String args[]){
                String str1 = new String("OKAY");
                String str2 = new String(str1);
                System.out.println(str1 == str2);
        }
}

Answer: Option B

Explanation:

12. What will be the output of the following program? public class Test{ public static void main(String args[]){ String s1 = "java"; String s2 = "java"; System.out.println(s1.equals(s2)); System.out.println(s1 == s2); } }

Answer: Option D

Explanation:

13. Which of these data type value is returned by equals() method of String class?

Answer: Option C

Explanation:
equals() method of string class returns boolean value true if both the string are equal and false if they are unequal.

14. The String method compareTo() returns

Answer: Option C

Explanation:

15. What could be output of the following fragment of code? public class Test{ public static void main(String args[]){ String x = "hellow"; int y = 9; System.out.println(x += y); } }

Answer: Option B

Explanation: