Exam: JAVA Programming
1. ________ is used to find and fix bugs in the Java programs
A. JVM
B. JRE
C. JKK
D. JDB
2. A SWITCH case statement in Java is a _____ control statement.
A. Iteration
B. Loop
C. Selection
D. Jump
3. An abstract class cannot be instantiated because it contains…
A. Abstract methods
B. Private methods
C. Static methods
D. Public methods
4. Array in java is _______.
A. Collection of similar elements
B. Collection of elements of different types
C. The data type of consisting of characters
D. None of these
5. ava program processing always starts with main() method
A. true
B. false
C.
D.
6. Can the Java program accept input from the command line?
A. Yes, using command-line arguments
B. Yes, by access command prompt
C. No
D. None of these
7. class box {
int width;
int height;
int length;
}
class mainclass {
public static void main(String args[]) {
box obj1 = new box();
box obj2 = new box();
obj1.height = 1;
obj1.length = 2;
obj1.width = 1;
obj2 = obj1;
System.out.println(obj2.height);
}
}
A. 1
B. 2
C. Runtime Error
D. Garbage value
8. Determine output:
public class Test{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.val = 1;
obj.call(obj);
System.out.println(obj.val);
}
}
class MyClass{
public int val;
public void call(MyClass ref){
ref.val++;
}
}
A. 6
B. 1
C. 4
D. 2
9. Encapsulation is _______.
A. Wrapping up of data and related functions into a single entity
B. Creating special methods
C. Creating special data structure
D. All of these
10. Evaluate the following Java expression, if x=3, y=5 and z=10:
++z + y - y + z + x++
A. 24
B. 23
C. 20
D. 25
11. How does one identify if a compilation unit is an interface or class from a .class file?
A. Extension of the compilation unit
B. Java source file header
C. The class and interface cannot be differentiated
D. The unit type must be used to postfix interface or class name
12. How many times 'Hello' is printed?
public class TestExam {
public static void main(String[] args){
for(int i = 0; i > 5; )
{
System.out.println("Hello");
}
}
}
A. 5
B. 4
C. 3
D. 0
13. How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args) {
for(int i = 0; i < 5; i = 5) {
System.out.println("Hello");
}
}
}
A. 5
B. 4
C. 2
D. 1
14. How many times 'Hello' is printed?
public class Test {
public static void main(String[] args){
for(int i = 0; i < 5; )
{
System.out.println("Hello");
}
}
}
A. 0
B. 1
C. 2
D. Infinite times
15. In Java, what is the number of primitive data types?
A. 4
B. 6
C. 2
D. 8
16. In Java, which keyword is used to define an abstract class?
A. abstract
B. class
C. interface
D. extends
17. In java, which method is automatically called when an object is created
A. start()
B. main()
C. init()
D. constructor()
18. In which case is the automatic type conversion possible?
A. Int to long
B. Long to int
C. Byte to Bit
D. float to byte
19. In which process, a local variable has the same name as one of the instance variables?
A. Serialization
B. Variable Shadowing
C. Abstraction
D. Multi-threading
20. Java is case sensitive language
A. true
B. false
C.
D.
21. Java supports both Primitive & Non-Primitive(User Defined) datatypes. Which one of the following is not a primitive datatype?
A. byte
B. short
C. long
D. class
22. Java supports single-line and multi-line comments very similar to C and C++
A. true
B. false
C.
D.
23. JDK stands for _______.
A. Java development kit
B. Java deployment kit
C. JavaScript deployment kit
D. None of these
24. On which platforms Java runs?
A. Windows
B. Mac OS
C. UNIX
D. All of these
25. Out of these methods, which one can be used for converting all the characters present in a String into an Array of char?
A. both getChars() & toCharArray()
B. both charAt() & getChars()
C. charAt()
D. all of the mentioned
26. Out of these methods, which one can be used for converting all the characters present in a String into an Array of characters?
A. both getChars() & toCharArray()
B. both charAt() & getChars()
C. charAt()
D. all of the mentioned
27. Out of these statements, which ones are incorrect?
A. The Brackets () have the highest precedence
B. The equal to = operator has the lowest precedence
C. The addition operator + and the subtraction operator - have an equal precedence
D. The division operator / has comparatively higher precedence as compared to a multiplication operator
28. Out of these, which one is the correct way of calling a constructor that has no parameters of the superclass A by the subclass B?
A. superclass.();
B. super(void);
C. super();
D. super.A();
29. Output of the code below
public class Main
{
private int a;
public Main(){
a = -10;
}
public static void main(String[] args) {
Main obj = new Main();
System.out.println(obj.a);
}
}
A. 0
B. Compilation Error
C. -10
D. Garbage Value
30. public class CppBuzz {
public static void main(String args[]) {
int a = 10;
String b = "10";
System.out.println(a + b);
}
}
A. 10"10"
B. Compilation Error
C. 20
D. 1010
31. public class CppBuzz {
public static void main(String args[]) {
int a = 10;
String b = "-10";
System.out.println(a + b);
}
}
A. 0
B. 10"-10"
C. 46305
D. Compilation Error
32. public class CppBuzz {
public static void main(String[] args){
int a = 10;
System.out.println(a*a--);
}
}
A. 100
B. 90
C. 81
D. 80
33. public class CppBuzz {
public static void main(String[] args){
int a = 10;
System.out.println(++a*a++);
}
}
A. 121
B. 132
C. 144
D. 100
34. public class CppBuzz {
public static void main(String[] args){
int a = 10;
System.out.println(a--*a--);
}
}
A. 100
B. 90
C. 99
D. 72
35. public class Main
{
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
int count = 0;
for(int i = 0; i < 5; i++) {
if(arr[i]%2==0)
count++;
}
System.out.print(count);
}
}
A. 3
B. 2
C. 1
D. 0
36. Select Odd one out from these about local variables
A. Local variables are declared in methods, constructors, or blocks
B. Local variables are created when the method, constructor or block is entered
C. the variable will be destroyed once it exits the method, constructor, or block
D. We can't create reference variables of Local variables
37. The result of dividing an integer number by 0 in Java is _____.
A. Error
B. Expectation
C. Infinite
D. None of these
38. The value of one primitive variable is assigned to another primitive variable by ___ in Java.
A. Pass by value
B. Pass by reference
C. None
D. All
39. What are packages in Java?
A. Methods of a friend class
B. Methods of the main class
C. Way to encapsulate a group of classes, sub-packages, and interface
D. All of these
40. What do you mean by nameless objects?
A. An object created by using the new keyword
B. An object of a superclass created in the subclass
C. An object without having any name but having a reference
D. An object that has no reference
41. What does the 'void' keyword indicate in a method declaration?
A. The method does not return any value
B. The method is private
C. The method returns an integer value
D. The method is static
42. What is a Loop in Java programming language?
A. A Loop is a block of code that is executed repeatedly as long as a condition is satisfied.
B. A Loop is a block of code that is executed only once if the condition is satisfied.
C. A Loop is a block of code that is executed more than 2 times if the condition is satisfied.
D. None
43. What is abstraction in Java?
A. Hiding data details
B. Hiding method implementations
C. the concept of showing only essential features of an object
D. Exposing all details
44. What is correct sequence of execution of any Java program?
A. Editing -> Compilation -> Class Loader -> Bytecode Verifier -> Execution
B. Editing -> Bytecode Verifier -> Compilation -> Class Loader -> Execution
C. Editing -> Compilation -> Bytecode Verifier -> Class Loader -> Execution
D. None of the above
45. What is false about constructor?
A. Constructors cannot be synchronized in Java
B. Java does not provide default copy constructor
C. Constructor can have a return type
D. "this" and "super" can be used in a constructor
46. What is method overloading in Java?
A. Defining multiple methods with the same name in the same class
B. Calling methods from another class
C. Using methods to load data from a file
D. Running methods in parallel threads
47. What is polymorphism in Java?
A. Performing a single task in multiple ways
B. Performing multiple tasks using multiple methods
C. Creating a new class for each task
D. All of these
48. What is Runnable?
A. Abstract class
B. Interface
C. Class
D. Method
49. What is the correct sequence of execution of any Java program?
A. Editing -> Compilation -> Class Loader -> Bytecode Verifier -> Execution
B. Editing -> Bytecode Verifier -> Compilation -> Class Loader -> Execution
C. Editing -> Compilation -> Bytecode Verifier -> Class Loader -> Execution
D. None of the above
50. What is the correct syntax to call a method named "myMethod" from an object "myObject"?
A. myObject.myMethod();
B. myMethod.myObject();
C. myMethod();
D. myObject->myMethod();
51. What is the extension of java code files?
A. .js
B. .txt
C. .class
D. .java
52. What is the main difference between encapsulation and abstraction in Java?
A. Encapsulation focuses on hiding data, while abstraction focuses on hiding implementation details.
B. Encapsulation focuses on hiding implementation details, while abstraction focuses on hiding data.
C. Encapsulation and abstraction are the same concepts.
D. Encapsulation and abstraction are unrelated concepts.
53. What is the main purpose of access modifiers in Java?
A. To provide default values
B. To control visibility and access
C. To define the class structure
D. To initialize objects
54. What is the output for the below code?
public class A
{
int add(int i, int j)
{
return i+j;
}
}
public class B extends A
{
public static void main(String argv[])
{
short s = 9;
System.out.println(add(s,6));
}
}
A. Compile fail due to error on line no 2
B. Compile fail due to error on line no 9
C. Compile fail due to error on line no 8
D. Compile fail due to error on line no 4
55. What is the output of the following code?
public class Main {
public static void main(String[] args) {
int arr[] = {1, 2, 3, 4, 5};
int count = 0;
for(int i = 0; i < 5; i++) {
if(arr[i] % 2 == 0) {
count++;
}
}
System.out.print(count);
}
}
A. 3
B. 2
C. 1
D. 0
56. What is the output of the following Java code?
public class CppBuzz {
public static void main(String args[]) {
int a = 10;
String b = "-10";
System.out.println(a + b);
}
}
A. 0
B. 10"-10"
C. 10-10
D. Compilation Error
57. What is the purpose of the "try" block in exception handing
A. It catches exceptions and handles them
B. It specifies the exception type
C. It contains the code that might throw an exception
D. It specifies the exception message
58. What will be the error in the following Java code?
byte b = 50;
b = b * 50;
A. b cannot contain value 50
B. b cannot contain value 100, limited by its range
C. No error in this code
D. * operator has converted b * 50 into int, which can not be converted to byte without casting
59. What will be the output of following Java code?
import java.util.Scanner;
class ThisKeyword {
private int a = 4;
private int b = 1;
void getSum(int a, int b) {
this.a = a;
this.b = b;
System.out.println(this.a + this.b);
}
}
public class Main {
public static void main(String args[]) {
ThisKeyword T = new ThisKeyword();
T.getSum(3, 5);
}
}
A. 5
B. 9
C. 8
D. 4
60. What will be the output of following Java code?
public class ConcatNull {
public static void main(String args[]) {
String str1 = "include";
String str2 = "help";
System.out.println(str1 + str2);
}
}
A. includehelp
B. include
C. help
D. None of these
61. What will be the output of following Java code?public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
System.out.println(i);
}
}
A. 1 2 3 4
B. 0 1 2 3
C. 1 2 3
D. 1 2 3 4
62. What will be the output of the following Java code?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
A. 32
B. 33
C. 24
D. 25
63. What will be the output of the following Java code?
public static void main(String args[])
{
int x = 8;
System.out.println(++x * 3 + " " + x);
}
A. 24 8
B. 24 9
C. 27 8
D. 27 9
64. What will be the output of the following Java code?
public static void main(String[] args) {
String[] fruits = {"MANGO", "APPLE", "BANANA", "PINEAPPLE"};
System.out.println(fruits[2]);
}
A. MANGO
B. APPLE
C. BANANA
D. PINEAPPLE
65. What will be the output of the following program?
public class MyFirst {
public static void main(String[] args) {
MyFirst obj = new MyFirst(n);
}
static int a = 10;
static int n;
int b = 5;
int c;
public MyFirst(int m) {
System.out.println(a + "," + b + "," + c + "," + n + "," + m);
}
// Instance Block
{
b = 30;
n = 20;
}
// Static Block
static
{
a = 60;
}
}
A. 10,5,0,20,0
B. 10,30,20
C. 60,5,0,20
D. 60,30,0,20,0
66. When an array is passed to a method, what does the method receive?
A. The reference of the array
B. A copy of the array
C. Length of the array
D. Copy of first element
67. When is the object created with new keyword?
A. At Run Time
B. At Compile time
C. Depends on the code
D. None
68. Which concept of Java is achieved by combining methods and attribute into a class?
A. Encapsulation
B. Inheritance
C. Polymorphism
D. Abstraction
69. Which Java keyword is used to access features of a package?
A. get
B. import
C. extends
D. All of these
70. Which keyword is used to define a method in Java?
A. method
B. def
C. func
D. public
71. Which method of the Class. class is used to determine the name of a class represented by the class object as a String?
A. getClass()
B. intern()
C. getName()
D. toString()
72. Which modifier restricts access to class members within the same class?
A. public
B. protected
C. private
D. static
73. Which of the below is invalid identifier with the main method?
A. public
B. static
C. private
D. final
74. Which of the following exception is thrown when divided by zero statement is executed?
A. NullPointerException
B. NumberFormatException
C. ArithmeticException
D. None
75. Which of the following is not a Java features?
A. Dynamic
B. Architecture Neutral
C. Use of pointers
D. Object-oriented
76. Which of the following is not an OOPS concept in Java?
A. Polymorphism
B. Inheritance
C. Compilation
D. Encapsulation
77. Which of the following is true about the anonymous inner class?
A. It has only methods
B. Objects can't be created
C. It has a fixed class name
D. It has no class name
78. Which of the following operator has more precedence?
A. ()
B. ++
C. *
D. >=
79. Which of the following operators has more precedence in Java?
A. -
B. +
C. *
D. >
80. Which of these cannot be used for a variable name in Java?
A. identifier & keyword
B. identifier
C. keyword
D. None of the above
81. Which of these operators is used to allocate memory for an object?
A. malloc
B. alloc
C. new
D. give
82. Which one of the following is an Unary operator in Java?
A. ()
B. *
C. +
D. ++
83. Which one of the following is Equality operator in Java?
A. >=
B. <=
C. ==
D. +=
84. Which OOP principle bundles data and methods into a single unit?
A. Inheritance
B. Abstraction
C. Encapsulation
D. Polymorphism
85. Who developed Java?
A. Gennady Korotkevich
B. John Carmack
C. James Gosling
D. Alan Turing
$floatBtn