Way2Java

Test Your Java 1

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 – 1

Read all the choices carefully, as there may be more than one correct answer, choose all the correct answers for each question.

  1. ________________________ makes Java platform-independent.
    a) JVM b) Java syntax c) Java API d) bytecodes e) none
  2. Java's keywords includes Null.
    a) True b) False
  3. Which occupies more number of bits of memory.
    a) double b) long c) both 4 b) occupies same d) depends on the value assigned e) none
  4. The object is created with new keyword
    a) at compile-time b) at run-time c) depends on the code d ) none
  5. int x = 0, y = 0 , z = 0 ;
    x = (+ + x + y – – ) * z + + ;
    What is the value of " x " after execution ?
    a) – 2 b) – 1 c) 0 d ) 1 e) 2
  6. int 4thhouse = 1234 ;
    System.out.println( 4thhouse ) ;
    a) 1234 b) displays error as the value assigned is more than the range of integer c) displays error as coding is not as per Java rules e) none
  7. int ++a = 100 ; System.out.println( ++a ) ;
    What is the output of the above fraction of code ?
    a) 100 b) displays error as + + a is not enclosed in double quotes in println statement c) compiler displays error as + + a is not a valid identifier d) none
  8. Integer.parseInt( ) method is used to convert an integer value to its string form.
    a) True b) False
  9. Java supports unsigned data types.
    a) True b) False
  10. One way of implementing data protection is declaring instance variables as private and methods as public.
    a) True b) False
  11. How many primitive data types Java defines ?
    a) 6 b) 8 c) 10 d) more than 10 e) none
  12. The variables declared in a class for the use of all methods of the class are called
    a) reference variables b) objects c) instance variables d ) none
  13. double STATIC = 2.5 ;
    System.out.println( STATIC ) ;
    The above fraction of code
    a) prints 2.5 b) raises an error as STATIC is used as a variable which is a keyword c) raises an exception e) none
  14. What is the range of data type int ?
    a) – ( 2^16 ) to ( 2^16 ) –1 b) – ( 2^15 ) to ( 2^15 ) –1 c) – ( 2^31 ) to ( 2^31 ) –1 d) – ( 2^32 ) to ( 2^32 ) –1 e) depends on the operating system on which Java is working f) none
  15. int Integer = 34 ;
    char String = 'S' ;
    System.out.println( Integer ) ;
    System.out.println( String ) ;
    What would be the output of the above fraction of code ?
    a) does not compile as Integer and String are API class names b) throws exception c) 34 d) S e) c and d f) none
  16. char k = 'A' ;
    System.out.println( k * k ) ;
    The above program raises a compilation error as arithmetic operations are not possible on characters. a) true b) false
  17. System.out.println( Math.floor( Math.random( ) ) ) ;
    The above statement always prints 0.0
    a) True b) False
  18. int x = 99 , y = 100 ;
    System.out.println( x / y ) ;
    What is the output of the above fraction of code ?
    a) does not compile b) 0 c) 0.99 d) none
  19. boolean b = true ;
    int i = ( int ) b ;
    System.out.println( i ) ;
    What is the output of the above fraction of code ?
    a) 116 ( the ASCII value of character t ) b) 98 ( the ASCII value of character b ) c) does not compile d) throws exception e) none
  20. System.out.println(25/4.0);
    System.out.println(25.0/4.0);
    System.out.println(25.0/4);
    The output of the above three println statements is same result.
    a) True b) False
  21. 21.

  22.      class Num  
         {
           Num(double x )   
           {
             System.out.println( x ) ;
           }   
         }
         class  Numbers  extends  Num   
         {
           public static void main(String[] args)   
           {
    	 Num num = new Num( 2 ) ;
            }     
         }

    What is the output of the above program ?
    a) 0 b) 2.0 c) error as mismatch between constructors d) none

  23. byte b = 50 ;
    b = b * 2 ;
    System.out.println( “ b = “ + b ) ;
    The above fraction of code prints b = 100.
    a) True b) False
  24. 23.

  25.      public class Numbers   
         {
           static int x  = 10 ;
           public static void main(String[] a)  
           {
    	 Numbers num = new Numbers( ) ; Numbers num1 = new Numbers( ) ;
    	 num.x  +=  1 ;
    	 System.out.println(  num.x + num1.x ) ;    
           }  
         }
    

    What is the output of the above program ?
    a) 20 b) 21 c) 22 d) does not compile e) throws exception e) none ( )

  26. Constructors can be declared final, if needed perhaps which you must have not tried.
    a) True b) False
  27. final methods cannot be overridden but overloaded ?
    a) True b) False

ANSWERS

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

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 1".