1.  What is the value returned by unction compareTo() if the invoking string is less than the string compared ?


zero
value less than zero
value greater than zero
None of the mentioned


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

2.  What is the value returned by function compareTo() if the invoking string is greater than the string compared ?


Zero
value less than zero
value greater than zero
None of the mentioned


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

3.  What is the output of this program ?
class output {
public static void main(String args[])
{
String s1 = ‘‘Hello i love java’‘;
String s2 = new String(s1);
System.out.println((s1 == s2) + ‘‘ ‘‘ + s1.equals(s2));
}
}


true true
false false
true false
false ture


Answer

 Option

The == operator compares two object references to see whether they refer to the same instance, where as equals() compares the content of the two objects.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

4.  What is the output of this program ?
class output {
public static void main(String args[])
{
String s1 = ‘‘Hello’‘;
String s2 = new String(s1);
String s3 = ‘‘HELLO’‘;
System.out.println(s1.equals(s2) + ‘‘ ‘‘ + s2.equals(s3));
}
}


true true
false false
true false
false ture


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

5.  What is the output of this program ?
class output {
public static void main(String args[])
{
String c = ‘‘Hello i love java’‘;
boolean var;
var = c.startsWith(‘‘hello’‘);
System.out.println(var);
}
}


true
false
0.
1


Answer

 Option

startsWith() method is case sensitive ‘‘hello’‘ and ‘‘Hello’‘ are treated differently, hence false is stored in var.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report