Test Your Java 3

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.

Test Your Java 3

  1. Arrays in Java work differently than what they do in C/C++.
    a) True b) False
  2. Arrays are
    a) objects b) object references c) primitive data types d) none
  3. char[] c = new char();
    char[] c = new char(4);
    char[] c = new char[];
    All the above three statements are invalid.
    a) True b) False
  4. int[] intarray1 = new int[] { 10, 20 };
    int[] intarray2 = { 10, 20 };

    We can form an array in the either way of the above statements.
    a) True b) False

  5. int intarray[3] = { 10, 20, 30 };
    The fraction of code outputs 20.
    a) True b) False
  6. It is possible to change the size of the array once it is created.
    a) True b) False
  7. .
         public class ZeroValue   
           public static void main(String args[])    
             Integer x[] = new Integer[3];

    what is the output of the above println statement?
    a) 0 b) 1 c) null d) does not compile e) throws exception

  8. int rates[] = {10, 20, 30 };
    What is the output of the above fragment of code?
    a) 0 b) 2 c) 3 d) does not compile e) throws exception f) none
  9. .
         class ArrayArgument    
           void display(int arrays[])   
             System.out.println(arrays[0] += 2);   
           public static void main(String args[])    
             int intarray[] = { 5, 10, 15 };
             ArrayArgument arrarg = new ArrayArgument();

    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

  10. Java, like C/C++, treates text string as an array of characters.
    a) True b) False
  11. String s1 = "RAMA\nKRISHNA";
    The above fraction code prints the output in two different lines.
    a) True b) False
  12. String s1 = new String("Hello");
    String s2 = new String("Hellow");
    System.out.println(s1 = s2);
    The output of the above fraction of code is
    a) Hello b) Hellow c) does not compile d) throws an exception e) none
  13. .
         class LogicalCompare        
           public static void main(String args[])      
             String  str1 = new String("OKAY");
             String  str2  =  new String(str1);
             System.out.println(str1 == str2);

    What is the output of the above program?
    a) displays error message b) true c) false d) 0 e) 1 f ) none

  14. String s1 = "java";
    String s2 = "java";
    System.out.println(s1 == s2);
    Both the above println statements returns true.
    a) True b) False
  15. String s1 = "SITHA" ;
    String s2 = "RAMA";
    System.out.println(s1.charAt(0) > s2.charAt(0));
    What is the output of the above code ?
    a) True b) False c) 0 d) does not compile e) throws exception f)none
  16. stringWidth() method is defined in _______________ class.
    a) String b) AWT c) Font d) FontMetrics e) none
  17. String x = "hellow";
    int y = 9;
    System.out.println(x += y);
    What could be output of the above fragment of code?
    a) does not compile b) throws an exception as string and int are not compatible for addition c) hellow9 d) 9hellow e) none
  18. toString() method is defined in
    a) java.lang.String b) java.lang.Object c) java.lang.util d) none
  19. "Toolbar".startsWith("bar", 4);
    The above statement returns
    a) False b) True c) does not return any thing d) displays error message e) none
  20. The String method compareTo() returns
    a) True b) False c) int value d) 1 e) -1 f) none
  21. String str1 = "abcde";
    System.out.println(str1.substring(1, 3));
    The above program prints bc.
    a) True b) False
  22. String str1 = "Hellow";
    What is the output of the above println statement
    a) True b) False c) 1 d) -1 e) 0 f) displays error message g) none
  23. .
         class ConcatEqual
           public static void main (String args[])     
             String str1 = "one";;
             String str2 = "two";
             System.out.println(str1.concat(str2).equals(str1 + str2)); 		

    a) 0 b) 1 c) no output d) -1 e) True f) False g) displays error message h) none

  24. String str1 = "Helloww".replace('l', 'w');
    In the above statement, the effect on string Helloww is
    a) the last occurrence of character w is replaced by l b) the first occurrence of l is replaced by w. c) all characters l are replaced by w.
    d) all characters w are replaced by l. e) displays error message
    f) the first occurrence of w is replaced by l. g) none

  25. char ch = 'x';
    What could be output of the above fragment of code ?
    a) Unicode value of character x. b) x c) displays error message d) none


1. a 2. a 3. a 4. a 5. b
6. b 7. c 8. d 9. a 10. b
11. a 12. b 13. c 14. a 15. a
16. d 17. c 18. b 19. b 20. c
21. a 22. d 23. e 24. c 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 3".

26 thoughts on “Test Your Java 3”

  1. Dear Sir,

    Can you please explain me Why a protected instance variable of super class in one package cannot be accessed by an object of super class inside the sub class in a different package?

  2. Dear sir,
    Can you pls explain me how the float value gets appended in the string?

    String x = “hellow”;
    float y = 9.0f;
    System.out.println(x =x+ y);

    I thought it would cause an error…

  3. Sir!
    Q) i am put 3+ exp on java.. if go any interview they asked project flow? how to explian? i am not genuine guy? or give me any idea how to escape?

Leave a Comment

Your email address will not be published.