

MCQOPTIONS
Saved Bookmarks
This section includes 1671 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
1251. |
What is the output of this program? class output { public static void main(String args[]) { StringBuffer sb=new StringBuffer("Hello"); sb.replace(1,3,"Java"); System.out.println(sb); } } |
A. | Hello java |
B. | Hellojava |
C. | HJavalo |
D. | Hjava |
Answer» D. Hjava | |
1252. |
What is the output of this program? class output { public static void main(String args[]) { StringBuffer c = new StringBuffer("Hello"); System.out.println(c.length()); } } |
A. | 4 |
B. | 5 |
C. | 6 |
D. | 7 |
Answer» C. 6 | |
1253. |
Which of the following are incorrect form of StringBuffer class constructor? |
A. | StringBuffer() |
B. | StringBuffer(int size) |
C. | StringBuffer(String str) |
D. | StringBuffer(int size , String str) |
Answer» E. | |
1254. |
Which of these method of class StringBuffer is used to get the length of sequence of characters? |
A. | length() |
B. | capacity() |
C. | Length() |
D. | Capacity() |
Answer» B. capacity() | |
1255. |
Which of these method of class StringBuffer is used to reverse sequence of characters? |
A. | reverse() |
B. | reverseall() |
C. | Reverse() |
D. | reverseAll() |
Answer» B. reverseall() | |
1256. |
What will s2 contain after following lines of code? StringBuffer s1 = "one"; StringBuffer s2 = s1.append("two") |
A. | one |
B. | two |
C. | onetwo |
D. | twoone |
Answer» D. twoone | |
1257. |
Which of these method of class StringBuffer is used to extract a substring from a String object? |
A. | substring() |
B. | Substring() |
C. | SubString() |
D. | None of the mentioned |
Answer» B. Substring() | |
1258. |
What is the output of this program? class output { class output { public static void main(String args[]) { char c[]={'A', '1', 'b' ,' ' ,'a' , '0'}; for (int i = 0; i < 5; ++i) { i++; if(Character.isDigit(c[i])) System.out.println(c[i]+" is a digit"); if(Character.isWhitespace(c[i])) System.out.println(c[i]+" is a Whitespace character"); if(Character.isUpperCase(c[i])) System.out.println(c[i]+" is an Upper case Letter"); if(Character.isLowerCase(c[i])) System.out.println(c[i]+" is a lower case Letter"); i++; } } } |
A. | a is a lower case Letter is White space character |
B. | b is a lower case Letter is White space character |
C. | 1 is a digit a is a lower case Letter |
D. | a is a lower case Letter 0 is a digit |
Answer» D. a is a lower case Letter 0 is a digit | |
1259. |
What is the output of this program? class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } } |
A. | Hello |
B. | olleH |
C. | HelloolleH |
D. | olleHHello |
Answer» C. HelloolleH | |
1260. |
What is the output of this program? class output { public static void main(String args[]) { StringBuffer c = new StringBuffer("Hello"); StringBuffer c1 = new StringBuffer(" World"); c.append(c1); System.out.println(c); } } |
A. | Hello |
B. | World |
C. | Helloworld |
D. | Hello World |
Answer» E. | |
1261. |
What is the output of this program? class output { public static void main(String args[]) { StringBuffer c = new StringBuffer("Hello"); c.delete(0,2); System.out.println(c); } } |
A. | He |
B. | Hel |
C. | lo |
D. | llo |
Answer» E. | |
1262. |
What is the output of this program? class output { public static void main(String args[]) { String a = "hello i love java"; System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v')); } } |
A. | 6 4 6 9 |
B. | 5 4 5 9 |
C. | 7 8 8 9 |
D. | 1 14 8 15 |
Answer» B. 5 4 5 9 | |
1263. |
What is the string contained in s after following lines of code? StringBuffer s new StringBuffer("Hello"); s.deleteCharAt(0); |
A. | Hell |
B. | ello |
C. | Hel |
D. | llo |
Answer» C. Hel | |
1264. |
Which of these method of class StringBuffer is used to find the length of current character sequence? |
A. | length() |
B. | Length() |
C. | capacity() |
D. | Capacity() |
Answer» B. Length() | |
1265. |
Which of these method of class StringBuffer is used to concatenate the string representation to the end of invoking string? |
A. | concat() |
B. | append() |
C. | join() |
D. | concatenate() |
Answer» C. join() | |
1266. |
Which of these class is used to create an object whose character sequence is mutable? |
A. | String() |
B. | StringBuffer() |
C. | Both of the mentioned |
D. | None of the mentioned |
Answer» C. Both of the mentioned | |
1267. |
What is the output of this program? class output { public static void main(String args[]) { String s = "Hello World"; int i = s.indexOf('o'); int j = s.lastIndexOf('l'); System.out.print(i + " " + j); } } |
A. | 4 8 |
B. | 5 9 |
C. | 4 9 |
D. | 5 8 |
Answer» D. 5 8 | |
1268. |
What is the output of this program? class output { public static void main(String args[]) { String s1 = "Hello World"; String s2 = s1.substring(0 , 4); System.out.println(s2); } } |
A. | Hell |
B. | Hello |
C. | Worl |
D. | World |
Answer» B. Hello | |
1269. |
What is the output of this program? class output { public static void main(String args[]) { String s1 = "Hello"; String s2 = s1.replace('l','w'); System.out.println(s2); } } |
A. | hello |
B. | helwo |
C. | hewlo |
D. | hewwo |
Answer» E. | |
1270. |
What is the output of this program? class output { public static void main(String args[]) { String s1 = "one"; String s2 = s1 + " two"; System.out.println(s2); } } |
A. | one |
B. | two |
C. | one two |
D. | compilation error |
Answer» D. compilation error | |
1271. |
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+"\""); } } |
A. | “”Hello World”” |
B. | “”Hello World” |
C. | “Hello World” |
D. | Hello world |
Answer» D. Hello world | |
1272. |
Which of the following statement is correct? |
A. | replace() method replaces all occurrences of one character in invoking string with another character |
B. | replace() method replaces only first occurrences of a character in invoking string with another character |
C. | replace() method replaces all the characters in invoking string with another character |
D. | replace() replace() method replaces last occurrence of a character in invoking string with another character |
Answer» B. replace() method replaces only first occurrences of a character in invoking string with another character | |
1273. |
What is the value returned by function compareTo() if the invoking string is greater than the string compared?vvvvv |
A. | zero |
B. | value less than zero |
C. | value greater than zero |
D. | none of the mentioned |
Answer» D. none of the mentioned | |
1274. |
Which of these method of class String is used to remove leading and trailing whitespaces? |
A. | startsWith() |
B. | trim() |
C. | Trim() |
D. | doTrim() |
Answer» C. Trim() | |
1275. |
What will s2 contain after following lines of code? String s1 = "one"; String s2 = s1.concat("two") |
A. | One |
B. | Two |
C. | onetwo |
D. | twoone |
Answer» D. twoone | |
1276. |
Which of these method of class String is used to extract a substring from a String object? |
A. | substring() |
B. | Substring() |
C. | SubString() |
D. | None of the mentioned |
Answer» B. Substring() | |
1277. |
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]); } } |
A. | ab |
B. | bc |
C. | ca |
D. | ac |
Answer» E. | |
1278. |
In the below code, which code fragment should be inserted at line 3 so that the output will be: “123abc 123abc”? 1 StringBuilder sb1 = new StringBuilder("123"); 2 String s1 = "123"; 3 // insert code here 4 System.out.println(sb1 + " " + s1); |
A. | sb1.append(“abc”); s1.append(“abc”); |
B. | sb1.append(“abc”); s1.concat(“abc”); |
C. | sb1.concat(“abc”); s1.append(“abc”); |
D. | sb1.append(“abc”); s1 = s1.concat(“abc”); |
Answer» E. | |
1279. |
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)); } } |
A. | true true |
B. | false false |
C. | true false |
D. | false true |
Answer» D. false true | |
1280. |
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)); } } |
A. | true true |
B. | false false |
C. | true false |
D. | false true |
Answer» E. | |
1281. |
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); } } |
A. | true |
B. | false |
C. | 0 |
D. | 1 |
Answer» C. 0 | |
1282. |
Which of these data type value is returned by equals() method of String class? |
A. | char |
B. | int |
C. | boolean |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
1283. |
What is the value returned by function compareTo() if the invoking string is less than the string compared? |
A. | zero |
B. | value less than zero |
C. | value greater than zero |
D. | none of the mentioned |
Answer» C. value greater than zero | |
1284. |
Which of these method of class String is used to check whether a given object starts with a particular string literal? |
A. | startsWith() |
B. | endsWith() |
C. | Starts() |
D. | ends() |
Answer» B. endsWith() | |
1285. |
Which of these methods is used to compare a specific region inside a string with another specific region in another string? |
A. | regionMatch() |
B. | match() |
C. | RegionMatches() |
D. | regionMatches() |
Answer» E. | |
1286. |
Which of these method of class String is used to compare two String objects for their equality? |
A. | equals() |
B. | Equals() |
C. | isequal() |
D. | Isequal() |
Answer» B. Equals() | |
1287. |
What is the output of this program? class output { public static void main(String args[]) { char ch; ch = "hello".charAt(1); System.out.println(ch); } } |
A. | h |
B. | e |
C. | I |
D. | o |
Answer» C. I | |
1288. |
What is the output of this program? class output { public static void main(String args[]) { char c[]={'a', '1', 'b' ,' ' ,'A' , '0'}; for (int i = 0; i < 5; ++i) { if(Character.isDigit(c[i])) System.out.println(c[i]+" is a digit"); if(Character.isWhitespace(c[i])) System.out.println(c[i]+" is a Whitespace character"); if(Character.isUpperCase(c[i])) System.out.println(c[i]+" is an Upper case Letter"); if(Character.isLowerCase(c[i])) System.out.println(c[i]+" is a lower case Letter"); i=i+3; } } } |
A. | a is a lower case Letter is White space character |
B. | b is a lower case Letter is White space character |
C. | a is a lower case Letter A is a upper case Letter |
D. | a is a lower case Letter 0 is a digit |
Answer» D. a is a lower case Letter 0 is a digit | |
1289. |
What is the output of this program? class output { public static void main(String args[]) { String a = "hello i love java"; System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o')); } } |
A. | 6 4 6 9 |
B. | 5 4 5 9 |
C. | 7 8 8 9 |
D. | 4 3 6 9 |
Answer» B. 5 4 5 9 | |
1290. |
What is the output of this program? class output { public static void main(String args[]) { String c = "Hello i love java"; int start = 2; int end = 9; char s[]=new char[end-start]; c.getChars(start,end,s,0); System.out.println(s); } } |
A. | Hello, i love java |
B. | i love ja |
C. | lo i lo |
D. | llo i l |
Answer» E. | |
1291. |
Which of these methods can be used to convert all characters in a String into a character array? |
A. | charAt() |
B. | both getChars() & charAt() |
C. | both toCharArray() & getChars() |
D. | all of the mentioned |
Answer» D. all of the mentioned | |
1292. |
What will be output of the following code? public class Boxer1 { Integer i; int x; public Boxer1(int y) { x = i+y; System.out.println(x); } public static void main(String[] args) { new Boxer1 (new Integer(4)); } } |
A. | The value “4” is printed at the command line |
B. | Compilation fails because of an error in line |
C. | A NullPointerException occurs at runtime |
D. | An IllegalStateException occurs at runtime |
Answer» E. | |
1293. |
In below code, what can directly access and change the value of the variable name? package test; class Target { public String name = "hello"; } |
A. | any class |
B. | only the Target class |
C. | any class in the test package |
D. | any class that extends Target |
Answer» D. any class that extends Target | |
1294. |
Which of these methods is an alternative to getChars() that stores the characters in an array of bytes? |
A. | getBytes() |
B. | GetByte() |
C. | giveByte() |
D. | Give Bytes() |
Answer» B. GetByte() | |
1295. |
Which of these method of class String is used to extract more than one character at a time a String object? |
A. | getchars() |
B. | GetChars() |
C. | Getchars() |
D. | getChars() |
Answer» E. | |
1296. |
What is the output of this program? class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); String s1 = "abcd"; int len1 = s1.length(); int len2 = s.length(); System.out.println(len1 + " " + len2); } } |
A. | 3 0 |
B. | 0 3 |
C. | 3 4 |
D. | 4 3 |
Answer» E. | |
1297. |
What is the output of this program? class String_demo { public static void main(String args[]) { int ascii[] = { 65, 66, 67, 68}; String s = new String(ascii, 1, 3); System.out.println(s); } } |
A. | ABC |
B. | BCD |
C. | CDA |
D. | ABCD |
Answer» C. CDA | |
1298. |
What is the output of this program? class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } } |
A. | a |
B. | b |
C. | c |
D. | abc |
Answer» E. | |
1299. |
Which of these constructors is used to create an empty String object? |
A. | String() |
B. | String(void) |
C. | String(0) |
D. | None of the mentioned |
Answer» B. String(void) | |
1300. |
Which of these method of class String is used to extract a single character from a String object? |
A. | CHARAT() |
B. | chatat() |
C. | charAt() |
D. | ChatAt() |
Answer» D. ChatAt() | |