Java Questions
READ THE QUESTIONS CAREFULLY AND SELECT THE CORRECT OPTION.
1. Which of these is a type of variable in Java?
A)Instance Variable
B)Local Variable
C)Static Variable
D)All of these
2.What will be the output of following Java code?
A)Hello
B)Bye
C)Error
D)All of these
3. What will be the output of following Java code?
A)1
B)No output
C)8
D)1357911
4) What part is used to compile, debug and execute java programs?
a) JRE
b) JIT
c) JDK
d) JVM
5) Which of these selection statements in Java do you have?
a) a break
b) continue
c) for ()
d) if ()
6) Arrays in java are-
a) Object References
b) Objects
c) Primitive Data type
d) None
7) Where does the system stores parameters and local variables whenever a method is invoked?
a) Heap
b) Stack
c) Objects
d) Reference
8) What will be the output of the following Java code?
a) 25
b) 24
c) 32
d) 33
9) Which of these is an incorrect string literal?
a) “Hello World”
b) “Hello\nWorld”
c) “\”Hello World\””
d) "Hello world"
10) Which is the super class of all exception classes
A. Exception
B. Object
C. Error
D. Throwable
11) Thread priority in Java is represented as?
A. int
B. Float
C. double
D. long
12) Which of these methods can be used to write console output?
A. writeln()
B. println()
C. write()
D. All of the mentioned
13) Which refers to a channel through which data flow from the source to the destination:
A. String
B. Character
C. Stream
D. Buffer
14) What is it called where child object gets killed if parent object is killed?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
15) What will be the output of the following Java program?
a) 0
b) 2
c) 4
d) None of the mentioned
16) What will be the output of the following Java program?
a) 0 0
b) 2 2
c) 4 1
d) 1 4
17) What will be the output of the following Java code?
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
18. What will be the output of the following Java code?
a) My Thread
b) Thread[My Thread,5,main]
c) Exception
d) Runtime Error
19) What is the name of the thread in output in the following Java program?
a) 0
b) 1
c) 4
d) 5
20) Which method is used to verify the actual and expected results in Junits?
a) assert()
b) equals()
c) ==
d) isEqual()
21) Find the output of the following code.
a. I
b. Compile Error
c. Throws Exception
d. 24 I
The correct answer is: 24 I
22) Find the output of the following program.
a. 50
b. COMPILER ERROR
c. 10
d. EXCEPTION
The correct answer is: COMPILER ERROR
23) Find the output of the following program.
a. 3
b. -127
c. 129
d. 127
The correct answer is: -127
24) Select the valid statement.
The correct answer is: char[] ch = new char[5]
25) Find the output of the following program.
a. 120 200 14
b. 120 200
c. 120 200 016
d. 120 200 16
The correct answer is: 120 200 14
25) When an array is passed to a method, what does the method receive?
a. copy of the array
b. LENGTH OF ARRAY
c. NONE
d. The reference of the array
The correct answer is: The reference of the array
26) In which of the following is toString() method defined?
a. NONE
b. java.lang.String
c. java.lang.Object
d. java.lang.util
The correct answer is: java.lang.Object
27) What does the following string do to given string str1.
a. Replaces single occurrence of ‘e’ to ‘s’.
b. Replaces all occurrences of ‘e’ to ‘s’.
c. NONE
d. Replaces single occurrence of ‘s’ to ‘e’.
The correct answer is: Replaces all occurrences of ‘e’ to ‘s’.
28) Which of the following exception is thrown when divided by zero statement is executed?
a. NullPointerException
b. ArithmeticException
c. NumberFormatException
d. NONE
The correct answer is: ArithmeticException
29) Which of the following is used to find and fix bugs in the program?
a. JVM
b. JDK
c. JDB
The correct answer is: JDB
0 Comments