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.
- ________________________ makes Java platform-independent.
a) JVM b) Java syntax c) Java API d) bytecodes e) none - Java's keywords includes Null.
a) True b) False - 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 - The object is created with new keyword
a) at compile-time b) at run-time c) depends on the code d ) none - 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 - 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 - 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 - Integer.parseInt( ) method is used to convert an integer value to its string form.
a) True b) False - Java supports unsigned data types.
a) True b) False - One way of implementing data protection is declaring instance variables as private and methods as public.
a) True b) False - How many primitive data types Java defines ?
a) 6 b) 8 c) 10 d) more than 10 e) none - 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 - 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 - 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 - 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 - 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 - System.out.println( Math.floor( Math.random( ) ) ) ;
The above statement always prints 0.0
a) True b) False - 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 - 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 - 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 -
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 - byte b = 50 ;
b = b * 2 ;
System.out.println( “ b = “ + b ) ;
The above fraction of code prints b = 100.
a) True b) False -
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 ( ) - Constructors can be declared final, if needed perhaps which you must have not tried.
a) True b) False - final methods cannot be overridden but overloaded ?
a) True b) False
21.
23.
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 |
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".