Test Your Java 7

Test Your Java 7

Test Your Java 7 and Test Your Java 8 are advanced questions. Answers are given for each question at the end of each test. Answering these questions increases your knowledge in Java and helps you a lot when you appear for interviews. Solving these basic questions is your first step for Certification Exams preparation.

  1. int i = -25;
    System.out.println(Math.sqrt(i));
    What is the output of the above fraction code ?
    a) 5 b) -5 c) a or b d) throws compilation error e) NaN f) none
  2. In case of insufficient memory, while creating an Object with new keyword, C++ returns null.
    What Java returns ?
    a) null b) does not return any thing c) displays run-time error d) displays compile-time error e ) none
  3. int x = 10;
    System.out.println((x > 10) ? 50.0 : 50);
    What could be output of the above fragment of code ?
    a) does not compile b) throws an exception c) 50.0 d) 50 e) none
  4. int x = 99, y = 100 ;
    System.out.println(x % y);
    What is the output of the above fraction of code ?
    a) 0 b) 99 c) 0.99 d) none
  5. double d = 45;
    int i = (int) d;
    The above explicit conversion takes place at
    a) compile time b) run time c) depends on the circumstance d) none
  6. .
    The above program compiles error free.
    a) True b) False
  7. byte b;
    int i = 257;
    b = (byte) i;
    System.out.println(“b = ” + b ) ;
    The output of the above fragment of code is
    a) b = 257 b) b = 256 c) b = 1 d) 0 e) none
  8. int x[] = new int[] { 10, 20, 30 };
    Arrays can also be created and intialized as in the above statement.
    a) True b) False
  9. .

    What is the output of the above println statemnt ?
    a) 0 b) 1 c) null d) does not compile e) throws exception f ) none
  10. .

    The above program
    a) both println statements prints the same value 7 b) one println prints 7 and the other 5 c) does not compile d) compiles but throws an exception e) none
  11. .
    What is the output of the above fraction of code ?
    a) end of code b) compiles but no output c) does not compile as else statement returns something in a void main method d) throws exception e) none
  12. .
    What is the output of the above program ?
    a) only static no method b) compiles but no output as no instance is created c) does not compile as static keyword is not followed by any method name d) none
  13. .
    What is the output of the above program ?
    a) SCJP Exam b) displays compile-time error message as main method is not as per syntax c) compiles but throws an exception at run time d) none
  14. .
    The above class
    a) compiles successfully and does not print any thing b) does not compile as there is no access specifier like public in the class declaration c) does not compile as return is not carrying any value d) b and c e) none
  15. The Cloneable interface does not contain any methods.
    a) True b) False
  16. Special characters like +, -, *, % , \n etc. should not be used in a String literal.
    a) True b) False
  17. String s1 = “SRIRAMA”;
    String s2 = “RAMA”;
    String s3 = s1 – s2;
    System.out.println(s3);
    What is the output of the above fraction of code ?
    a) SRI b) SRIRAMA c) RAMA d) does not compile e) throws exception f) none
  18. charAt(int) method is included in class
    a) String b) StringBuffer c) Object d) a and b e) none
  19. byte charArray[] = { ‘S’,’C’,’J’,’P’ };
    System.out.println(charArray[0]);
    The above code:
    a) prints S b) prints 83 c) compilation error d) raises an exception e) none
  20. StringTokenizer class belongs to the package
    a) java.lang b) java.util c) java.io d) java.string e) none
  21. toString( ) method is a member of
    a) Object b) Thread c) String d) a, b and c e) a and c f) none
  22. The getClass() method is defined in class
    a) Object b) File c) Class d) none
  23. Void is the wrapper implementation of void.
    a) True b) False
  24. System.out.println(Math.sin(x));
    In the above statement, the value of x should be in
    a) degrees b) radians c) none
  25. .

    The above code
    a) prints Bill amount: 110.0 b) raises a compilation error as default constructor is not defined c) raises an exception d) system hangs e) none

ANSWERS

1. e 2. c 3. c 4. b 5. a
6. b 7. c 8. a 9. c 10. a
11. b 12. a 13. c 14. a 15. a
16. b 17. d 18. d 19. b 20. b
21. d 22. a 23. a 24. b 25. b

Your Rating

Correct Answers
1 to 5 : Poor
6 t0 10: Below average
11 t0 15: Average
16 to 20: Good
Above 20: Extraordinary

Pass your comments and suggestions for the improvement of this "Test Your Java 7".

8 thoughts on “Test Your Java 7

  1. Maurice

    Question 3 has an extra parentheses. I believe this is a typo given the answer isn’t fail compilation.

    System.out.println((x > 10) ? 50.0 : 50));

          1. Ganga prasad pipper

            System.out.println((x > 10) ? 50.0 : 50));

            it’s showing output as
            50.0

            The statement (x>10) gives false, so the output will be 50.
            But how it is 50.0
            sir, please explain
            Thank you..

Leave a Reply

Your email address will not be published. Required fields are marked *