Witscale Test Center

Sample test


Sample test

1. Consider the following code.

 

                1.            public class StringTest {

                2.              public static void main(String [] args) {

                3.                String str1 = "xxy";

                4.                String str2 = "yyz";

                5.                String str3 = str2;

                6.                str2 = "zzx";

                7.                System.out.println(str1 + str2 + str3);

                8.              }

                9.            }

 

What will be the result of executing the class StringTest?

 

A.      xxyzzxyyz

B.      xxyyyzzzx

C.      xxyxxyzzx

D.     xxyxxyxxy

E.      Compilation fails at line 5.

F.       An exception is thrown at runtime at line 6.

 

 

2. Consider the following code.

 

                            1.            public class StringTest {

                            2.              public static void main(String [] args) {

                            3.                String str = "Once upon a ";

                            4.                str.concat("time").toLowerCase();

                            5.                String anotherStr = str.replace('i','I');

                            6.                System.out.println(anotherStr);

                            7.              }

                            8.            }

 

What will be the result of executing the class StringTest?

 

A.      Once upon a time

B.      Once upon a tIme

C.      once upon a tIme

D.     Once upon a

E.      A runtime exception is thrown at runtime at line 5.

 

 

3. Consider the following code fragment.

 

4.    String a = new String("Hello");

5.    String b = "World" + a;

6.    System.out.println(a + b);

 

How many String objects will be created when you execute this code?

 

A.      1

B.      2

C.      3

D.     4

E.      5

 

 

4. Consider the following code fragment.

 

4.    String a = "Hello";

a.concat(" ");

5.    StringBuffer b = new StringBuffer("World");

b.append(‘!’).replace(‘l’,’L’);

6.    System.out.println(a + b);

 

What will be the result when you execute the code?

 

A.      HeLLo WorLd

B.      HelloWorLd

C.      HeLLo WorLd!

D.     HelloWorLd!

E.      Compilation fails at line 8

 

 

5. Consider the following code fragment.

 

4.       String a = "Tomato";

5.       a = a.concat("paste").substring(4,8) ;

6.       a = a + ‘z’;

7.       a.append(“ ring!”);

8.       System.out.println(a);

 

What will be the result when you execute the code?

 

A.      atopz ring

B.      atopaz ring

C.      Topaz ring

D.     TomatoPaste ring!

E.      Compilation fails at line 6

F.       Compilation fails at line 7

 

 

6. Which of the following would result in double value -11.0?

 

A.      Math.round(-12.7);

B.      Math.ceil(-11.2);

C.      Math.round(-11.7);

D.     Math.floor(-11.9);

E.      Math.floor(-10.7);

 

 

7. Consider the following class.

 

                            1.              public class MathTester {

                            2.                public static void main(String[] args) {

                            3.                  double temperatures[] = { 48.5, 75.7, 67 };

                            4.                  String[] cities = { "San Francisco", "Paris", "Kyoto" };

                            5.                  for (int i = 0; i < cities.length; i++) {

                            6.                    double d = Math.ceil(temperatures[i]);

                            7.                    long l = Math.round(temperatures[i]);

                            8.                    if (d == l)

                            9.                      System.out.println(cities[i].toUpperCase());

                        10.                    }

                        11.                }

                        12.              }

 

What will be the result when you execute the code?

 

A.      Paris

B.      San Francisco

C.      SAN FRANCISCO

D.     PARIS

E.      KYOTO

F.       Compilation fails.

 

 

8. Which of the following would result in a double value 100.0 ?

 

A.      Math.max(100,75);

B.      Math.min(100,101.2);

C.      Math.abs(-100.0);

D.     Math.sqrt(10000);

E.      Math.abs(100.1);

 

 

9. Consider the following class.

 

                   1.              public class RandomTester {

                2.                public static void main(String[] args) {

                3.                  for (int i = 0; i < 10; i++) {

                4.                    int no = (int) (100 * Math.random());

                5.                      System.out.println(no);

                6.                    }

                7.                }

                8.              }

 

Which of the following values can be a part of the result when you execute this application?

 

A.      100.0

B.      0

C.      0.78

D.     98

E.      100

F.       It is impossible to tell.

 

 

10. Which of the following will correctly print the sine of 90 degrees?

 

A.      System.out.println(Math.sin(90));

B.      System.out.println(Math.sin(Math.toDegrees(90)));

C.      System.out.println(Math.sin(Math.toRadians(90)));

D.     System.out.println(Math.toRadians(90).sin(90));

E.      System.out.println(Math.sin(90,”degrees”));

F.       None of the above

 

 

11. Which of the following declarations will successfully compile?

 

A.      Long no1 = new Long(12345678L);

B.      Float no2 = new Float(12.34);

C.      Integer no3 = new Integer(‘a’);

D.     Byte no4 = new Byte(“6”);

E.      Boolean no5 = new Boolean(“false”);

 

 

12. Consider the following code fragment.

 

                4.               int n1 = Integer.parseInt("10");

                5.                int n2 = Integer.parseInt("10", 2);

                6.                int n3 = Integer.parseInt("10", 16);

                7.                long n4 = Long.parseLong("10");

                8.                if(n1 == n2)

                9.                   System.out.print("1 ");

            10.                if(n1 == n3)

            11.                   System.out.print("2 ");

            12.                if(n1 == n4)

            13.                   System.out.print("3 ");

 

What will be the result?

 

A.      1 2 3

B.      1 3

C.      3

D.     2 3

E.      Compilation fails.

 

 

13. Consider the following class.

 

                            1.            public class X {

                            2.              public static void main(String[] args) {

                            3.                int n1 = Integer.parseInt("1010");

                            4.                int n2 = Integer.parseInt("10", 2);

                            5.                int n3 = Integer.parseInt(15);

                            6.                int n4 = Integer.parseInt("15");

                            7.                int n5 = n4.intValue();

                            8.                int n6 = Integer.valueOf("15");

                            9.              }

                        10.            }

 

Which of the lines can cause compilation error?

 

A.      Line 3

B.      Line 4

C.      Line 5

D.     Line 6

E.      Line 7

F.       Line 8

 

 

14. Consider the following class.

 

                            1.            public class WrapperTest {

                            2.              public static void main(String[] args) {

                            3.                Boolean b1 = new Boolean("FALSE");

                            4.                Double d = new Double(8.7);

                            5.                boolean b2 = Math.floor(7.8) == d.intValue();

                            6.                if (b2 & true)

                            7.                  System.out.print("check1 ");

                            8.                  if (b1 & b2)

                            9.                  System.out.print("check2 ");

                        10.               System.out.println("done");

                        11.              }

                        12.            }

 

Which one line can be removed so that the class will successfully compile?

 

A.      Line 3

B.      Line 5

C.      Line 6

D.     Line 8

E.      None of the above. The code compiles as it is.

 

 

15. Consider the following code fragment.

 

                            1.            public class WrapperTest {

                            2.              public static void main(String[] args) {

                            3.                Boolean b = new Boolean("tRUE");

                            4.                Integer i1 = new Integer(0);

                            5.                Integer i2 = new Integer(0);

                            6.                int i3 = i1.intValue();

                            7.                float f = Float.parseFloat("0.0f");

                            8.                Double d = Double.valueOf("1.8");

                            9.                WrapperTest obj1 = new WrapperTest();

                        10.                WrapperTest obj2 = new WrapperTest();

                        11.                // ????

                        12.              }

                        13.            }

 

Which of the following statements when placed on line 9 will print true?

 

A.      System.out.println(b.equals("true"));

B.      System.out.println(i3 == f);

C.      System.out.println(i1.equals(i2));

D.     System.out.println(obj1 == obj2);

E.      System.out.println(obj1.equals(obj2));