Strings


  1. What is the output of this program?

    public class Result
    {
    public static void main(String[]args)
    {
    String[] array = { "for", "tea", "too" };
    String num= (array.length > 2) ? array[2]: null;
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The value at the 0th position will be assigned to the variable num.


  1. What is the output of this program?

    public class stringClass_Example
    {
    public static void main(String args[])
    {
    String str = "Interview";
    String str1 = "Mania";
    String str2 = "Interview";
    System.out.println(str.equals(str1) + " " + str.equals(str2));
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    equals() is method of class String, it is used to check equality of two String objects, if they are equal, true is retuned else false.
    output: false true



  1. Which of these keywords is used to refer to member of base class from a subclass?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.


  1. Which of the following statements are incorrect?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Strings in Java are immutable that is they can not be modified.



  1. Which of these method of String class can be used to test to strings for equality?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    equals()