Java MCQ Questions

1) Which of the following does not find the square of a number?
a) Math.pow(a,2)
b) a*a
c) Math.sqrt(a,2)
d) All of the above
Answer

a) Math.sqrt(a,2)

2) What type of value is returned by Math.sqrt( )?
a) int
b) float
c) double
d) All
Answer

c) double

3) Which of the following syntax is the correct one to find the square root of a number?
a) sqrt(a)
b) Math.sqrt(a)
c)Squareroot(a)
d) None
Answer

b) Math.sqrt(a)

4) Name the class that is used for different Mathematical functions.
a)Java.Math
b) Java.Power
c)Java.Sqrt
d)None
Answer

a) Java.Math

5) Give the output of the Math.abs(x); when x =-9.99
a)-9.99
b)9.99
c)0.99
d)None
Answer

b) 9.99

6) Give the output of Math.sqrt(x); when x = 9.0
a) 3
b) 3.0
c)3.00
d)All
Answer

b) 3.0

7) In a switch case, when the switch value does not respond to any case then the execution transfers to :
a) a break statement
b)a default case
c)a loop
d)none
Answer

a) a break statement

8) Which of the following is a compound statement?
a) p = Integer.parseInt(in.readLine());
b) c=++a;
c) if(a>b) a++; b-- ;
d) a=4;
Answer

c) if(a>b) a++; b-- ;

9) Condition is essentially formed by using:
a) Arithmetic operators
b) Relational operators
c) Logical operators
d) All
Answer

d) All

10) If ((a>b)&&(a>c)), then which of the given statements is true?
a) b is the smallest number
b) b is the greatest number
c) a is the greatest number
d) all of the above
Answer

c) a is the greatest number

11) If (a>b) c=a; else c=b; It can be written as:
a)c = (b>a)?a:b;
b) c = (a!=b)?a:b;
c) c =(a>b)?a:b;
d) None
Answer

d) None

12) If a,b and c are the sides of a triangle then which of the following statement is true for: if(a!=b && b!=c)?
a)Equilateral triangle
b) Scalene triangle
c) Isosceles triangle
d) All of the above
Answer

b) Scalene triangle

13) Two arithmetical expressions can be compared with the if statement ,using:
a) Arithmetic operators
b) Relational operators
c) Logical operators
d) None
Answer

b) Relational operators

14) Which of the following is a conditional statement?
a) if
b) goto
c) for
d) none
Answer

a) if

15) Which of the following statement accomplishes a 'fall through' ?
a) for statement
b) switch case statement
c) if-else
d) none
Answer

b) switch case statement

16) A Java program executes but doesn't give the desired output.It is due to:
a) The logical error in the program
b) The syntax error in the program
c) The runtime error in the program
d) None
Answer

b) The syntax error in the program

17) Which of the following statement is exit controlled loop?
a) for
b) while
c) do while
d) if-else
Answer

c) do while

18) When execution of the statements are repeated sequentially a number of times in a program, the construct is known as :
a) iteration
b) sequence
c) selection
d) none
Answer

a) iteration

19) Which of the following loop does not execute even once if the condition is false in the begininning?
a) do-while
b) while
c) for
d) nested loop
Answer

a) do-while

20) To execute a loop 10 times, which of the following statement will be used:
a) for(i=6; i<=26; i=i+2)
b) for(i=3; i<=30; i=i+3)
c) for(i=0; i<10; i++)
d) all of the above
Answer

b) for(i=3; i<=30; i=i+3)

21) Which of these is a wrapper for data type int?
a) Integer
b) Long
c) Byte
d) Double
Answer

a) Integer

22) Which of the following is not an OOPS concept in Java?
a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation
Answer

c)Compilation

23) To execute a loop 10 times, which of the following statement will be used:
a) for(i=6; i<=26; i=i+2)
b) for(i=3; i<=30; i=i+3)
c) for(i=0; i<10; i++)
d) all of the above
Answer

b) for(i=3; i<=30; i=i+3)

24)Which of the following is a type of polymorphism in Java Programming?
a) Multiple polymorphism
b) Compile time polymorphism
c) Multilevel polymorphism
d) Execution time polymorphism
Answer

b) Compile time polymorphism

25) What is Truncation in Java? Answer:
a) Floating-point value assigned to a Floating type
b) Floating-point value assigned to an integer type
c) Integer value assigned to floating type
d) Integer value assigned to floating type
Answer

b)Floating-point value assigned to an integer type

26) What is the extension of compiled java classes?
a) .txt
b) .js
c) .class
d) .java
Answer

c) .class

27) To execute a loop 10 times, which of the following statement will be used:
a) for(i=6; i<=26; i=i+2)
b) for(i=3; i<=30; i=i+3)
c) for(i=0; i<10; i++)
d) all of the above
Answer

b) for(i=3; i<=30; i=i+3)

28) Which of these are selection statements in Java? Answer: d
a) break
b) continue
c) for()
d) if()
Answer

d) if()

29) Which of these keywords is used to define interfaces in Java?
a) intf
b) Intf
c) interface
d) Interface
Answer

c) interface

30) Which of the following is a superclass of every class in Java?
a) ArrayList
b) Abstract class
c) Object class
d) String
Answer

c) Object class

31)Which of the below is not a Java Profiler?
a) JProfiler
b) Eclipse Profiler
c) JVM
d) JConsole
Answer

c) JVM

32)Which of these packages contains the exception Stack Overflow in Java?
a) java.io
b) java.system
c) java.lang
d) java.util
Answer

c) java.lang

33) Which of these statements is incorrect about Thread?:
a) start() method is used to begin execution of the thread
b) run() method is used to begin execution of a thread before start() method in special cases
c) A thread can be formed by implementing Runnable interface only
d) A thread can be formed by a class that extends Thread class
Answer

b) run() method is used to begin execution of a thread before start() method in special cases

34) Which of these keywords are used for the block to be examined for exceptions?
a) check
b) throw
c) catch
d) try
Answer

d) try

35) Which one of the following is not an access modifier?
a) Protected
b) Void
c) Public
d) Private
Answer

b) Public

36) What is the numerical range of a char data type in Java?
a)0 to 256
b) -128 to 127
c) 0 to 6553w5
d) 0 to 32767
Answer

c) 0 to 65535

37) Which class provides system independent server side implementation?
a) Server
b) ServerReader
c) Socket
d) ServerSocket
Answer

d)ServerSocket

38) Which component is used to compile, debug and execute the java programs?
a) JRE
b) JIT
c) JDK
d) JVM
Answer

c) JDK

39) Which one of the following is not a Java feature?
a) Object-oriented
b) Use of pointers
c) Portable
d) Dynamic and Extensible
Answer

b) Use of Pointers

40) Which of these cannot be used for a variable name in Java?
a) identifier & keyword
b) identifier
c) keyword
d) none of the mentioned
Answer

c) identifier

41) Which environment variable is used to set the java path?
a) MAVEN_Path)
b) JavaPATH
c) JAVA
d) JAVA_HOME
Answer

d) JAVA_HOME

42) Which of this method can be used to make the main thread to be executed last among all the threads?
a) stop()
b) sleep()
c) join()
d) call()
Answer

b) sleep()

43) Which of this method is used to find out that a thread is still running or not?
a) run()
b) Alive())
c) isAlive()
d) checkRun()
Answer

c) isAlive()

44) What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?
a) 0 & 256
b) 0 & 1
c) 1 & 10
d) 1 & 256
Answer

c) 1 & 10

45) Which of these method waits for the thread to terminate?
a) sleep()
b) isAlive()
c) join()
d) stop()
Answer

c) join()

Go Checkout :- More Mcq Questions on Java.
Go Checkout :- Blog on Java Programming language.