1. what is the output of following program:

  1. package com.instanceofjavaforus;
  2.  
  3. public class StringDemo{
  4.  
  5.  public static void main(String[] args) {
  6.  
  7.       String str="I love java";
  8.       System.out.println(str.charAt(3));
  9. }
  10. }



2. what is the output of following program:

  1. package com.instanceofjavaforus;
  2.  
  3. public class StringDemo{
  4.  
  5.  public static void main(String[] args) {
  6.  
  7.       String str="I love java";
  8.       System.out.println(str.length());
  9. }
  10. }








3. what is the output of following program:

  1. package com.instanceofjavaforus;
  2.  
  3. public class StringDemo{
  4.  
  5.  public static void main(String[] args) {
  6.  
  7.       String str1="abc";
  8.       String str2="abc";
  9.  
  10.        System.out.println(str1.equals(str2));
  11. }
  12. }






4. what is the output of following program:

  1. package com.instanceofjavaforus;
  2.  
  3. public class StringDemo{
  4.  
  5.  public static void main(String[] args) {
  6.  
  7.         String str1 = "abc";
  8.         String str2 = "abc";
  9.         String str3= new String("abc");
  10.  
  11.         System.out.println("str1 == str2 ? "+(str1==str2));
  12.         System.out.println("str1 == str3 ? "+(str1==str3));
  13.         System.out.println("str1 equals str3 ? "+(str1.equals(str3)));
  14.  
  15.  
  16. }
  17. }






Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

4 comments for String programing interview questions

  1. Explain any one.
    4th program.
    please...

    ReplyDelete
    Replies
    1. one is stored in heap and other is stored in class memory.so if we compare it is not true.if we use ëqualstoignorecase" it will be true

      Delete
    2. == operator check only reference and equals method check content

      Delete
  2. str1 == str2 ? "+(str1==str2));
    this will compare the references of the object of str1 and str2(note 1:when object is created with string literal it will get stored in the constant pool region of the heap segment..
    note 2:when object is created with new keyword it will get stored in the Non-constant pool region of the heap segment..
    note3: constant pool region doesnot allow duplicates of objects
    note 4:non-constant pool region allows duplicates)

    ReplyDelete

Select Menu