Sample MCQ

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1. double d = Math.round ( 2.5 + Math.

random() );
a) 2
b) 3.0
c) 4.0
d) Error

2. What is the output of the Java code snippet?

a) 1,2,
b) 1,2,3,4,5,
c) 1,2,4,5,
d) 3,6,

3. int a = 10, b = 20;


if (a < b){
if (a > b){
System.out.println("HELLO WORLD");
}
else {
System.out.println("WELCOME"); }
}
a) HELLO WORLD
b) WELCOME
c) error
d) HELLO WORLD WELCOME

4. ......... is a sequence of characters that represent values in a program and are


stored in variables
a) literals
b) String
c) data
d) variable
5. the parameters that appear in the method invocation are called.............
a) actual parameter
b) formal parameter
c) dummy parameter
d) reference parameters

6. how is polymorphism implemented in Java?


a) by constructor
b) by method overloading
c) by pure methods
d) by impure methods

7. ........... help in dividing complex program into manageable code blocks.


a) class
b) package
c) methods
d) loops
8. A Loop in Java language may contain ___.
a) for loop
b) switch statement
c) do while loop
d) all of these

9. System.out.print(Math.pow(Math.sqrt(9),3);
a) 9
b) -9.0
c) 27.0
d) Syntax error

10. for (int i = 0; ; i++)


System.out.println("HELLO");
a) Syntax Error
b) Runtime Error
c) HELLO
d) HELLO (infinitely)

11. what type of errors are caught by the compiler?


a) runtime error
b) logical error
c) syntax error
d) all of these
12. .......... is the act of representing essential features without including background
details.
a) inheritance
b) abstraction
c) method
d) class

13. how many values a constructor can return.....


a) any number of values
b) 2 values
c) cannot return any value
d) 1 value

14. Java provides ........ types of conditional statements.


a) 1
b) 2
c) 3
d) 5

15. System.out.println(Math.floor(-0.88));
a) -1.0
b) -0.0
c) 0.0
d) 1.0

16. ........ is a template to create similar objects that share common characteristics
and behaviour.
a) a method
b) a procedure
c) an attribute
d) a class

17. ...... methods are those methods that do not change the original state of an
object.
a) pure
b) impure
c) ambiguous
d) static
18. the statement System.out.print(2+2+" four "+2+2); give the output
a) 4 four 4
b) 22 four 4
c) 4 four 22
d) Syntax error

19. A ......... conversion are performed by the programmer using the cast operator.
a) explicit type
b) implicit type
c) type promotion
d) widening

20. JVM is a/an .......... .


a) compiler
b) assembler
c) interpreter
d) machine

21. Java applications .........


a) are platform dependent
b) are platform independent
c) cannot run on Apple computer
d) can be run only Windows

22. which package provides classes that are fundamental to the design of the Java
programming language such as string and math class
a) java.util
b) java.io
c) java.lang
d) java.basic

23. how many times the following loop will run?


for(int i=0; i > Math.cbrt(1000); i+=2)
a) 5
b) 0
c) 50
d) 99
24. Find the odd one.
a) Double
b) Long
c) String
d) Char

You might also like