Olete.in
Articles
Mock Tests
🧪 Java MCQ Quiz Hub
Java Mcq Question Set 2
Choose a topic to test your knowledge and improve your Java skills
1. Which is the predefined package
Lang package
util package
io package
None of above
2. Java intermediate code is known as
Byte code
First code
Mid code
None of above
3. Which command is used for interpretation of java program
Java
javap
javac
none of above
4. What is meaning of jar
java array
java architecture
java archived
none of these
5. Which of the following command is used to compile the Java program
java
javac
javap
none of these
6. What do you mean by javap
java compiler
java debugger
java Interpreter
java Disassemble
7. What is jdb
java Disassemble
java Interpreter
java compiler
java debugger
8. Java is known as _______stage language
1
2
3
4
9. Which driver is called as thin-driver in JDBC
Type-1 driver
Type-2 driver
Type-3 driver
Type-4 driver
10. How many transaction isolation levels are defined in java.sql.Connection interface
6
2
5
3
11. Which method of java is invoked by JVM to reclaim the inaccessible memory location
reclaim() method
finalize() method
final() method
both b and c
12. ____ allows java code to run in the JVM to call and be called by native applications
JNI
FJI
NJI
JFI
13. Interfaces helps in which type of inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance
None of above
14. Which method of the Applet class displays the result of applet code on screen
paint() method
main() method
run() method
drawString() method
15. Which command disassembles a class file
javacmd
javaamd
javap
java
16. In which we clone the object and their constituent parts
Deep cloning
Shallow cloning
Both of above
None of above
17. Which driver is efficient and always preferable for using JDBC applications
Type-1 driver
Type-2 driver
Type-3 driver
Type-4 driver
18. Executable applet is
.class file
.java file
.java html
.applet file
19. Which keyword is used while using interface
throw
throws
extend
implements
20. Which keyword represents object of the present class
this
static
package
interface
21. Hot java is
Web browser
Java environment
System software
IDE
22. javah stands for
java dissasamebler
java header file
java interpreter
java compiler
23. Main method parameter has which type of data type
int
char
string
double
24. How many keywords are available in java
24
48
96
192
25. Smallest individual unit in java program is known as
token
string
literal
operator
26. Suppose a class has public visibility. In this class we define a protected method. Which of the following statements is correct?
From within protected methods you do not have access to public methods.
This method is only accessible from inside the class itself and from inside all subclasses.
In a class, you cannot declare methods with a lower visibility than the visibility of the class in which it is defined.
This method is accessible from within the class itself and from within all classes defined in the same package as the class itself.
27. The object is created with "new" keyword
At Compile-time
At run-time
Depends on the code
None of these
28. ate regarding the following classes? class A{private int i; protected int j; } class B extends A{ private int k; protected int m; }
An object of B contains data fields j, k, m
An object of B contains data fields k, m
An object of B contains data fields j, m
An object of B contains data fields i, j, k, m
29. A package is a collection of
Classes and Interfaces
Classes
Editing tools
Editing tools and Interfaces
30. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?
Declare the method with the keyword public.
Declare the method with the keyword private.
Do not declare the method with any accessibility modifiers.
Declare the method with the keyword public and private.
31. Choose the correct statement public class Circle{ private double radius; public Circle(double radius){ radius = radius; } }
The program has a compilation error because we cannot assign radius to radius.
The program has a compilation error because it does not have a main method.
The program does not compile because Circle does not have a default constructor.
The program will compile, but we cannot create an object of Circle with a specified radius. The object will always have radius 0.
32. Choose the correct statement : Restriction on static methods are-
They cannot refer this or super in any way.
They must only access static data.
They can only call other static methods.
All of the above
33. Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class.
abstract
static
volatile
final
34. In Java arrays are
objects
object references
primitive data type
None of the above
35. Which one of the following is a valid statement?
char[] c = new char&l
char[] c = new char&l
char[] c = new char&l
char[] c = new char&l
36. What is the result of compiling and running the following code? public class Test{ public static void main(String[] args){ int[] a = new int[0]; System.out.print(a.length); } }
0
1
compile error
None of the above
37. What is output of the following code: public class Test{public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++)System.out.print(x[i] + " "); } }
120 200 16
120 200 14
120 200 016
016 is a compile error. It should be written as 16
38. What will be the output? public class Test{ public static void main(String[] arg{ int[] a = new int[4]; a[1] = 1; a = new int[2]; System.out.println("a[1] is " + a[1]); } }
a[1] is 0
a[1] is 1
a[1] is 2
Compile error
39. When you pass an array to a method, the method receives ________ .
The length of the array.
The reference of the array.
A copy of the array.
A copy of the first element.
40. Which will legally declare, construct, and initialize an array?
int [] myList = {
int [] myList = (5, 8, 2);
int myList [] [] = {4,9,7,0};
int myList [] = {4, 3, 7};
41. What is the value of a[1] after the following code is executed? int[] a = {0, 2, 4, 1, 3}; for(int i = 0; i < a.length; i++) a[i] = a[(a[i] + 3) % a.length];
0
1
2
3
42. The output of the following fraction of code is public class Test{ public static void main(String args[]){ String s1 = new String("Hello"); String s2 = new String("Hellow"); System.out.printl
Hellow
Hello
Compilation error
None of these
43. Output : public class Test{ public static void main(String args[]){ String x = "hellow"; int y = 9; System.out.println(x += y); } }
hellow9
9hellow
Compilation error
None of these
44. toString() method is defined in
java.lang.util
java.lang.Object
java.lang.String
None of these
45. The String method compareTo() returns
TRUE
FALSE
an int value
1
46. What will be the output? String str1 = "abcde"; System.out.println(str1.substring(1, 3));
abc
ab
bc
cba
Submit