java-programming-java-lang-class Related Question Answers

1. What will be the output of the program? String x = new String("xyz"); String y = "abc"; x = x + y; How many String objects have been created?





2. What will be the output of the program? public class WrapTest { public static void main(String [] args) { int result = 0; short s = 42; Long x = new Long("42"); Long y = new Long(42); Short z = new Short("42"); Short x2 = new Short(s); Integer y2 = new Integer("42"); Integer z2 = new Integer(42); if (x == y) / Line 13 / result = 1; if (x.equals(y) ) / Line 15 / result = result + 10; if (x.equals(z) ) / Line 17 / result = result + 100; if (x.equals(x2) ) / Line 19 / result = result + 1000; if (x.equals(z2) ) / Line 21 / result = result + 10000; System.out.println("result = " + result); } }





3. What will be the output of the program? public class BoolTest { public static void main(String [] args) { int result = 0; Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("true"); Boolean b3 = new Boolean("tRuE"); Boolean b4 = new Boolean("false"); if (b1 == b2) / Line 10 / result = 1; if (b1.equals(b2) ) / Line 12 / result = result + 10; if (b2 == b4) / Line 14 / result = result + 100; if (b2.equals(b4) ) / Line 16 / result = result + 1000; if (b2.equals(b3) ) / Line 18 / result = result + 10000; System.out.println("result = " + result); } }





4. What will be the output of the program? public class ObjComp { public static void main(String [] args ) { int result = 0; ObjComp oc = new ObjComp(); Object o = oc; if (o == oc) result = 1; if (o != oc) result = result + 10; if (o.equals(oc) ) result = result + 100; if (oc.equals(o) ) result = result + 1000; System.out.println("result = " + result); } }





5. What will be the output of the program? public class Example { public static void main(String [] args) { double values[] = {-2.3, -1.0, 0.25, 4}; int cnt = 0; for (int x=0; x < values.length; x++) { if (Math.round(values[x] + .5) == Math.ceil(values[x])) { ++cnt; } } System.out.println("same results " + cnt + " time(s)"); } }





6. What will be the output of the program? public class Test178 { public static void main(String[] args) { String s = "foo"; Object o = (Object)s; if (s.equals(o)) { System.out.print("AAA"); } else { System.out.print("BBB"); } if (o.equals(s)) { System.out.print("CCC"); } else { System.out.print("DDD"); } } }





7. What will be the output of the program? String x = "xyz"; x.toUpperCase(); / Line 2 / String y = x.replace('Y', 'y'); y = y + "abc"; System.out.println(y);



8. What will be the output of the program? int i = (int) Math.random();





9. What will be the output of the program? class A { public A(int x){} } class B extends A { } public class test { public static void main (String args []) { A a = new B(); System.out.println("complete"); } }





10. What will be the output of the program? int i = 1, j = 10; do { if(i++ > --j) / Line 4 / { continue; } } while (i < 5); System.out.println("i = " + i + "and j = " + j); / Line 9 /





11. What will be the output of the program? public class ExamQuestion7 { static int j; static void methodA(int i) { boolean b; do { b = i<10 | methodB(4); / Line 9 / b = i<10 || methodB(8); / Line 10 / }while (!b); } static boolean methodB(int i) { j += i; return true; } public static void main(String[] args) { methodA(0); System.out.println( "j = " + j ); } }





12. 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 / }





13. What will be the output of the program? class Q207 { public static void main(String[] args) { int i1 = 5; int i2 = 6; String s1 = "7"; System.out.println(i1 + i2 + s1); / Line 8 / } }





14. What will be the output of the program? public class SqrtExample { public static void main(String [] args) { double value = -9.0; System.out.println( Math.sqrt(value)); } }





15. What will be the output of the program? String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);




16. 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"); } } }





17. What will be the output of the program? System.out.println(Math.sqrt(-4D));





18. What will be the output of the program? interface Foo141 { int k = 0; / Line 3 / } public class Test141 implements Foo141 { public static void main(String args[]) { int i; Test141 test141 = new Test141(); i = test141.k; / Line 11 / i = Test141.k; i = Foo141.k; } }





19. What will be the output of the program? String a = "newspaper"; a = a.substring(5,7); char b = a.charAt(1); a = a + b; System.out.println(a);





20. What will be the output of the program? public class StringRef { public static void main(String [] args) { String s1 = "abc"; String s2 = "def"; String s3 = s2; / Line 7 / s2 = "ghi"; System.out.println(s1 + s2 + s3); } }





21. What will be the output of the program? public class Test138 { public static void stringReplace (String text) { text = text.replace ('j' , 'c'); / Line 5 / } public static void bufferReplace (StringBuffer text) { text = text.append ("c"); / Line 9 / } public static void main (String args[]) { String textString = new String ("java"); StringBuffer textBuffer = new StringBuffer ("java"); / Line 14 / stringReplace(textString); bufferReplace(textBuffer); System.out.println (textString + textBuffer); } }





22. What will be the output of the program? class Tree { } class Pine extends Tree { } class Oak extends Tree { } public class Forest1 { public static void main (String [] args) { Tree tree = new Pine(); if( tree instanceof Pine ) System.out.println ("Pine"); else if( tree instanceof Tree ) System.out.println ("Tree"); else if( tree instanceof Oak ) System.out.println ( "Oak" ); else System.out.println ("Oops "); } }





23. 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);





24. What will be the output of the program? String a = "ABCD"; String b = a.toLowerCase(); b.replace('a','d'); b.replace('b','c'); System.out.println(b);




25. 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); } }





Terms And Service:We do not guarantee the accuracy of available data ..We Provide Information On Public Data.. Please consult an expert before using this data for commercial or personal use | Powered By:Omega Web Solutions
© 2002-2017 Omega Education PVT LTD...Privacy | Terms And Conditions