Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Home
»
Java Programming
»
Java.lang Class
What will be the output of the program? String d = "bookkeeper"; d.substring(1,7); d = "w" + d; d.append("woo"); /* Line 4 */ System.out.println(d);
wookkeewoo
wbookkeeper
wbookkeewoo
Compilation fails.
Correct Answer:
Compilation fails.
Explanation:
In line 4 the code calls a
StringBuffer
method,
append()
on a
String
object.
← Previous Question
Next Question→
More Questions from
Java.lang Class
What will be the output of the program? System.out.println(Math.sqrt(-4D));
What will be the output of the program? public class NFE { public static void main(String [] args) { String s = "42"; try { s = s.concat(".5"); /* Line 8 */ double d = Double.parseDouble(s); s = Double.toString(d); int x = (int) Math.ceil(Double.valueOf(s).doubleValue()); System.out.println(x); } catch (NumberFormatException e) { System.out.println("bad number"); } } }
What will be the output of the program? String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);
What will be the output of the program? public class ExamQuestion6 { static int x; boolean catch() { x++; return true; } public static void main(String[] args) { x=0; if ((catch() | catch()) || catch()) x++; System.out.println(x); } }
What will be the output of the program? try { Float f1 = new Float("3.0"); int x = f1.intValue(); byte b = f1.byteValue(); double d = f1.doubleValue(); System.out.println(x + b + d); } catch (NumberFormatException e) /* Line 9 */ { System.out.println("bad number"); /* Line 11 */ }
What will be the output of the program (in jdk1.6 or above)? public class BoolTest { public static void main(String [] args) { Boolean b1 = new Boolean("false"); boolean b2; b2 = b1.booleanValue(); if (!b2) { b2 = true; System.out.print("x "); } if (b1 & b2) /* Line 13 */ { System.out.print("y "); } System.out.println("z"); } }
Discussion & Comments
No comments yet. Be the first to comment!
Name:
Comment:
Post Comment
Join Discussion
Discussion & Comments