0% found this document useful (0 votes)
20 views

String_Handling_MCQ_Question

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

String_Handling_MCQ_Question

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

GIRI’S TECH HUB –PVT.

LTD – PUNE – 9175444433, 9049361265

MCQ Question First


class MNR
{
void method1(String st , int x)
{ st = new String("bye");
x = x+1;
}
public static void main(String s[])
{ String str1 = "hi";
String str2 = "hi";
int a = 1;
new MNR().method1(str1, 10);
new MNR().method1(str2, 20);
System.out.println(str1 + " " + str2 + " " + a);
}
}
MCQ2
class Ques_64
{ public static void main(String s[])
{ String str1 = "abc";
String str2 = new String (str1);
String str3 = new String ("abc");
String str4 = new String ("Abc");
System.out.print((str1 == str3) + “ “);
System.out.print(str4.equalsIgnoreCase(str1) + “ “);
System.out.print((str2 == str3) + “ “);
System.out.print(str2 == str4);
}
}
MCQ3
class Ques_66 {
public static void main(String args[])
{ if(args.length == 1 | args[1].equals("testing"))
{
System.out.println("testing");
}
else {
System.out.println(args[0]);
}

Visit: http://www.techhubindia.org Download APP : GIRI’S TECH HUB Page 1


GIRI’S TECH HUB –PVT.LTD – PUNE – 9175444433, 9049361265

}
}
MCQ4
class Test {
public void sendstring(String s1, StringBuffer s2)
{ s1 = s1+s2.toString();
s2.append(s1);
s1 = null;
s2 = null;
}
public static void main(String [] args)
{ String str = "AAA";
StringBuffer sbr = new StringBuffer("BBB");
new Test().sendstring(str, sbr);
System.out.print("str=" + str + “ “);
System.out.print("sbr=" +sbr);
}
}
MCQ5
public class Switchtest
{ public static void main(String args[]) {
String str;
String s;
String s1 = new String("i");
String s2 = new String("j");
String s3 = new String("k");
str = s2;
s2 = null;//1
str = s1 + s2 + s3;//2
s1 = null;//3
str = null;//4
s3 = null;//6
}
}
MCQ6
class Ques97 {
public static void main(String args[]) {
String str1 , str2 , str3;
str3 = new String("jim");

Visit: http://www.techhubindia.org Download APP : GIRI’S TECH HUB Page 2


GIRI’S TECH HUB –PVT.LTD – PUNE – 9175444433, 9049361265

str1 = new String("jack");


str2 = str1 ;
str1 = new String("jill");
str3 = str2;
System.out.println(str3);
}
}
MCQ7
public class StrEqual {
public static void main(String[] args) {
String s1 = "hello";
String s2 = new String("hello");
String s3 = "hello";
if (s1 == s2) {
System.out.println("s1 and s2 equal");
} else {
System.out.println("s1 and s2 not equal");
}
if (s1 == s3) {
System.out.println("s1 and s3 equal");
} else {
System.out.println("s1 and s3 not equal");
}
}
}
MCQ8
public class Test {
public static void main(String[] args) {
String str = null;
System.out.println(str.valueOf(10));
}
}

MCQ9
public class Test {
public static void main(String[] args) {
String s = new String("5");
System.out.println(1 + 10 + s + 1 + 10);
}

Visit: http://www.techhubindia.org Download APP : GIRI’S TECH HUB Page 3


GIRI’S TECH HUB –PVT.LTD – PUNE – 9175444433, 9049361265

}
MCQ10
public class Test {
public static void main(String[] args) {
String str = null;
switch (str) { // #1
case "null":
System.out.println("null string"); // #2
break;
}
}
}
MCQ11
public class Test {
public static void main(String[] args) {
String s1 = null;
System.out.println(s1); //line 2
System.out.println(s1.toString()); //line 3
}
}
MCQ12
public class Test {
public static void main(String[] args) {
String s1 = "hello";
String s2 = new String("hello");
s2 = s2.intern();
System.out.println(s1 == s2);
}
}
MCQ13
public class Test {
public static void main(String[] args) {
String s1 = "abc";
StringBuffer s2 = new StringBuffer(s1);
System.out.println(s1.equals(s2));
}
}
MCQ14
String s1 = "Java";
Visit: http://www.techhubindia.org Download APP : GIRI’S TECH HUB Page 4
GIRI’S TECH HUB –PVT.LTD – PUNE – 9175444433, 9049361265

String s2 = "Java";
StringBuilder sb1 = new StringBuilder();
sb1.append("Ja").append("va");
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
System.out.println(sb1.toString() == s1);
System.out.println(sb1.toString().equals(s1));

Visit: http://www.techhubindia.org Download APP : GIRI’S TECH HUB Page 5

You might also like