1.  In the below code, which code fragment should be inserted at line 3 so that the output will be: ‘‘123abc 123abc’‘ ?
StringBuilder sb1 = new StringBuilder(‘‘123’‘);
String s1 = ‘‘123’‘;
// insert code here
System.out.println(sb1 + ‘‘ ‘‘ + s1);


sb1.append(‘‘abc’‘); s1.append(‘‘abc’‘);
sb1.append(‘‘abc’‘); s1.concat(‘‘abc’‘);
sb1.concat(‘‘abc’‘); s1.append(‘‘abc’‘);
sb1.append(‘‘abc’‘); s1 = s1.concat(‘‘abc’‘);


Answer

 Option

append() is stringbuffer method and concat is String class method. append() is stringbuffer method and concat is String class method.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

2.  What is the output of this program ?
class A {
int i;
int j;
A() {
i = 1;
j = 2;
}
}
class Output {
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}


true
false
String associated with obj1
compilation error


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 c = ‘‘ Hello World ‘‘;
String s = c.trim();
System.out.println(‘‘\’‘‘‘+s+’‘\’‘‘‘);
}
}


‘‘‘‘Hello World’‘‘‘
‘‘‘‘Hello World’‘
‘‘Hello World’‘
Hello world


Answer

 Option

No answer description available for this question.

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 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

5.  What is the output of this program ?
class output {
public static void main(String args[])
{
String chars[] = {‘‘a’‘, ‘‘b’‘, ‘‘c’‘, ‘‘a’‘, ‘‘c’‘};
for (int i = 0; i < chars.length; ++i)
for (int j = i + 1; j < chars.length; ++j)
if(chars[i].compareTo(chars[j]) == 0)
System.out.print(chars[j]);
}
}


ab
bc
ca
ac


Answer

 Option

No answer description available for this question.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report