**Theory-Based Questions (1-50)**
**1. Which of the following is a low-level language?**
A) Java
B) Python
C) Assembly Language
D) C++
**Answer: C**
**2. What is the function of an assembler?**
A) Converts high-level code to machine code
B) Converts assembly code to machine code
C) Converts bytecode to machine code
D) Converts source code to object code
**Answer: B**
**3. Which principle of OOP allows a function to be used for multiple purposes?**
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Data Abstraction
**Answer: C**
**4. Which Java package is imported by default?**
A) java.util
B) java.io
C) java.lang
D) java.awt
**Answer: C**
**5. What is the extension of a Java source code file?**
A) .class
B) .java
C) .exe
D) .obj
**Answer: B**
**6. Which keyword is used to create an object in Java?**
A) create
B) new
C) object
D) allocate
**Answer: B**
**7. What is the size of the 'int' data type in Java?**
A) 8 bits
B) 16 bits
C) 32 bits
D) 64 bits
**Answer: C**
**8. Which escape sequence is used for a new line?**
A) \t
B) \n
C) \r
D) \\
**Answer: B**
**9. Which of the following is a valid identifier?**
A) 2variable
B) variable-name
C) _variable
D) class
**Answer: C**
**10. What is the result of 10 % 3?**
A) 1
B) 3
C) 0
D) 10
**Answer: A**
**11. Which operator has the highest precedence?**
A) +
B) *
C) ()
D) =
**Answer: C**
**12. What does JVM stand for?**
A) Java Virtual Machine
B) Java Visual Machine
C) Java Verified Method
D) Java Variable Memory
**Answer: A**
**13. Which method is used to read an integer from the Scanner class?**
A) next()
B) nextInt()
C) readInt()
D) getInt()
**Answer: B**
**14. Which of the following is a logical error?**
A) Missing semicolon
B) Dividing by zero
C) Using wrong formula
D) Misspelling a keyword
**Answer: C**
**15. Which function returns the square root of a number?**
A) Math.pow()
B) Math.sqrt()
C) Math.cbrt()
D) Math.log()
**Answer: B**
**16. What is the output of Math.ceil(5.4)?**
A) 5.0
B) 5.4
C) 6.0
D) 5.0
**Answer: C**
**17. Which loop is exit-controlled?**
A) for
B) while
C) do-while
D) nested for
**Answer: C**
**18. Which statement is used to terminate a program?**
A) break
B) exit(0)
C) System.exit(0)
D) return
**Answer: C**
**19. What is the default value of a boolean variable?**
A) true
B) false
C) 0
D) null
**Answer: B**
**20. Which of these is a wrapper class?**
A) int
B) Integer
C) Int
D) INT
**Answer: B**
**21. What is the output of 5 + 6 + "7"?**
A) 18
B) 567
C) 117
D) 57
**Answer: C**
**22. Which method is used to convert a string to an integer?**
A) toInt()
B) parseInt()
C) convertInt()
D) valueOf()
**Answer: B**
**23. What is the range of the 'byte' data type?**
A) -128 to 127
B) -32768 to 32767
C) -2^31 to 2^31-1
D) 0 to 255
**Answer: A**
**24. Which concept is also known as data hiding?**
A) Inheritance
B) Polymorphism
C) Encapsulation
D) Abstraction
**Answer: C**
**25. Who developed the Java language?**
A) Dennis Ritchie
B) James Gosling
C) Bjarne Stroustrup
D) Bill Gates
**Answer: B**
**26. What is the initial name of Java?**
A) Coffee
B) Oak
C) Green
D) Pine
**Answer: B**
**27. Which of these is not a primitive data type?**
A) int
B) float
C) String
D) char
**Answer: C**
**28. What is the output of 9 / 2?**
A) 4.5
B) 4
C) 5
D) 4.0
**Answer: B**
**29. Which keyword is used to define a constant?**
A) const
B) final
C) static
D) constant
**Answer: B**
**30. What is the output of Math.abs(-10.5)?**
A) -10.5
B) 10
C) 10.5
D) 11
**Answer: C**
**31. Which method returns a random number between 0.0 and 1.0?**
A) Math.random()
B) Math.rand()
C) Random()
D) Math.rnd()
**Answer: A**
**32. What is the purpose of the 'else' statement?**
A) To execute code when 'if' is true
B) To execute code when 'if' is false
C) To check multiple conditions
D) To terminate the program
**Answer: B**
**33. Which symbol is used for single-line comments?**
A) /*
B) //
C) <!--
D) #
**Answer: B**
**34. What is the output of 10 > 9 && 9 > 8?**
A) true
B) false
C) 1
D) 0
**Answer: A**
**35. Which function converts a character to uppercase?**
A) toUpper()
B) upperCase()
C) toUpperCase()
D) convertUpper()
**Answer: C**
**36. What is the default delimiter in Scanner?**
A) Comma
B) Semicolon
C) Space
D) Newline
**Answer: C**
**37. Which method is used to read a whole line of text?**
A) next()
B) nextLine()
C) readLine()
D) getLine()
**Answer: B**
**38. What is the output of 5 + 2 * 3?**
A) 21
B) 11
C) 17
D) 10
**Answer: B**
**39. Which of these is a relational operator?**
A) &&
B) ||
C) !
D) >=
**Answer: D**
**40. What is the result of 10 / 0?**
A) 0
B) Infinity
C) ArithmeticException
D) 10
**Answer: C**
**41. Which class is used for input operations in Java?**
A) Input
B) Scanner
C) Reader
D) System.in
**Answer: B**
**42. What is the output of Math.round(4.5)?**
A) 4
B) 5
C) 4.5
D) 5.0
**Answer: B**
**43. Which principle allows a class to inherit properties from another class?**
A) Polymorphism
B) Encapsulation
C) Inheritance
D) Abstraction
**Answer: C**
**44. What is the output of "Hello".length()?**
A) 4
B) 5
C) 6
D) Error
**Answer: B**
**45. Which method is used to compare two strings?**
A) compare()
B) equals()
C) ==
D) same()
**Answer: B**
**46. What is the output of 3 == 3.0?**
A) true
B) false
C) Error
D) 0
**Answer: A**
**47. Which keyword is used to prevent inheritance?**
A) private
B) final
C) static
D) sealed
**Answer: B**
**48. What is the output of 10 / 3.0?**
A) 3
B) 3.0
C) 3.333...
D) 3.33
**Answer: C**
**49. Which function returns the smallest integer greater than or equal to a number?**
A) Math.floor()
B) Math.ceil()
C) Math.round()
D) Math.rint()
**Answer: B**
**50. What is the purpose of the 'break' statement in a switch?**
A) To exit the program
B) To skip the current iteration
C) To prevent fall-through
D) To terminate the loop
**Answer: C**
---
### **Output Prediction Questions (51-100)**
**51. What is the output of the following?**
```java
System.out.println(5 + 3 + "2");
```
A) 82
B) 532
C) 10
D) 52
**Answer: A**
**52. What is the output?**
```java
int a = 5;
System.out.println(a++ + ++a);
```
A) 10
B) 11
C) 12
D) 13
**Answer: C**
**53. What is the output?**
```java
System.out.println(Math.sqrt(25));
```
A) 5
B) 5.0
C) 25
D) 2.5
**Answer: B**
**54. What is the output?**
```java
System.out.println(10 > 5 ? "Yes" : "No");
```
A) Yes
B) No
C) true
D) false
**Answer: A**
**55. What is the output?**
```java
int x = 10;
if(x > 5) {
System.out.println("A");
} else {
System.out.println("B");
}
```
A) A
B) B
C) No output
D) Error
**Answer: A**
**56. What is the output?**
```java
System.out.println("Hello\nWorld");
```
A) Hello\nWorld
B) Hello World
C) Hello
World
D) Error
**Answer: C**
**57. What is the output?**
```java
int a = 10, b = 20;
System.out.println(a + b + "30");
```
A) 3030
B) 102030
C) 30
D) 30
**Answer: A**
**58. What is the output?**
```java
System.out.println(Math.pow(2, 3));
```
A) 6
B) 8
C) 8.0
D) 9.0
**Answer: C**
**59. What is the output?**
```java
System.out.println(7 % 3);
```
A) 1
B) 2
C) 3
D) 0
**Answer: A**
**60. What is the output?**
```java
int a = 5;
a += a++ + ++a;
System.out.println(a);
```
A) 16
B) 17
C) 18
D) 19
**Answer: C**
**61. What is the output?**
```java
System.out.println(Math.ceil(4.1));
```
A) 4.0
B) 4.1
C) 5.0
D) 5
**Answer: C**
**62. What is the output?**
```java
System.out.println(Math.floor(4.9));
```
A) 4.0
B) 4.9
C) 5.0
D) 5
**Answer: A**
**63. What is the output?**
```java
System.out.println(Math.round(4.5));
```
A) 4
B) 5
C) 4.5
D) 5.0
**Answer: B**
**64. What is the output?**
```java
System.out.println(Math.min(10, 20));
```
A) 10
B) 20
C) 30
D) 0
**Answer: A**
**65. What is the output?**
```java
System.out.println(Math.max(10, 20));
```
A) 10
B) 20
C) 30
D) 0
**Answer: B**
**66. What is the output?**
```java
System.out.println("Result: " + (10 + 20 * 3));
```
A) Result: 90
B) Result: 70
C) Result: 60
D) Result: 30
**Answer: B**
**67. What is the output?**
```java
int a = 10;
if(a == 10)
System.out.println("Ten");
else
System.out.println("Not Ten");
```
A) Ten
B) Not Ten
C) No output
D) Error
**Answer: A**
**68. What is the output?**
```java
System.out.println(!"Hello".equals("hello"));
```
A) true
B) false
C) Hello
D) hello
**Answer: A**
**69. What is the output?**
```java
int a = 5;
System.out.println(a > 5 ? "Big" : "Small");
```
A) Big
B) Small
C) 5
D) Error
**Answer: B**
**70. What is the output?**
```java
System.out.println(10 / 2 * 5);
```
A) 1
B) 25
C) 10
D) 50
**Answer: B**
**71. What is the output?**
```java
System.out.println(2 + 3 + "4" + 5 + 6);
```
A) 5456
B) 23456
C) 5456
D) 5456
**Answer: A**
**72. What is the output?**
```java
int x = 10;
System.out.println(x++);
System.out.println(++x);
```
A) 10, 12
B) 11, 12
C) 10, 11
D) 11, 11
**Answer: A**
**73. What is the output?**
```java
System.out.println(Math.abs(-10.5));
```
A) -10.5
B) 10.5
C) 10
D) 11
**Answer: B**
**74. What is the output?**
```java
System.out.println(10 == 10.0);
```
A) true
B) false
C) Error
D) 0
**Answer: A**
**75. What is the output?**
```java
System.out.println(5 > 3 && 3 < 2);
```
A) true
B) false
C) 1
D) 0
**Answer: B**
**76. What is the output?**
```java
System.out.println(5 > 3 || 3 < 2);
```
A) true
B) false
C) 1
D) 0
**Answer: A**
**77. What is the output?**
```java
System.out.println(!(5 > 3));
```
A) true
B) false
C) 1
D) 0
**Answer: B**
**78. What is the output?**
```java
int a = 10;
a = a + 5;
System.out.println(a);
```
A) 10
B) 15
C) 5
D) Error
**Answer: B**
**79. What is the output?**
```java
System.out.println("Hello".charAt(1));
```
A) H
B) e
C) l
D) o
**Answer: B**
**80. What is the output?**
```java
System.out.println("Hello".substring(1, 3));
```
A) Hel
B) el
C) lo
D) ell
**Answer: B**
**81. What is the output?**
```java
System.out.println(10 + 20 + "30" + 40 + 50);
```
A) 30304050
B) 303090
C) 30304050
D) 1204050
**Answer: A**
**82. What is the output?**
```java
int a = 10, b = 20;
int c = a > b ? a : b;
System.out.println(c);
```
A) 10
B) 20
C) 30
D) 0
**Answer: B**
**83. What is the output?**
```java
System.out.println(Math.cbrt(27));
```
A) 3.0
B) 9.0
C) 27.0
D) 1.0
**Answer: A**
**84. What is the output?**
```java
System.out.println(Math.rint(4.5));
```
A) 4.0
B) 5.0
C) 4.5
D) 5
**Answer: A**
**85. What is the output?**
```java
System.out.println(Math.ceil(-4.5));
```
A) -4.0
B) -5.0
C) -4.5
D) 4.0
**Answer: A**
**86. What is the output?**
```java
System.out.println(Math.floor(-4.5));
```
A) -4.0
B) -5.0
C) -4.5
D) 4.0
**Answer: B**
**87. What is the output?**
```java
System.out.println(Math.round(-4.5));
```
A) -4
B) -5
C) -4.0
D) -5.0
**Answer: A**
**88. What is the output?**
```java
int a = 5;
System.out.println(a--);
System.out.println(--a);
```
A) 5, 3
B) 4, 3
C) 5, 4
D) 4, 4
**Answer: A**
**89. What is the output?**
```java
System.out.println(10 / 4);
```
A) 2
B) 2.5
C) 3
D) 2.0
**Answer: A**
**90. What is the output?**
```java
System.out.println(10.0 / 4);
```
A) 2
B) 2.5
C) 3
D) 2.0
**Answer: B**
**91. What is the output?**
```java
System.out.println('A' + 1);
```
A) A1
B) 66
C) B
D) 65
**Answer: B**
**92. What is the output?**
```java
System.out.println((char)('A' + 1));
```
A) A
B) B
C) 66
D) 65
**Answer: B**
**93. What is the output?**
```java
int a = 10;
if(a = 10)
System.out.println("Ten");
```
A) Ten
B) Error
C) No output
D) Compilation error
**Answer: D**
**94. What is the output?**
```java
System.out.println(5 + "5" - 5);
```
A) 50
B) 5
C) 55
D) Error
**Answer: D**
**95. What is the output?**
```java
System.out.println(1 + 2 + "3" + 4 * 5);
```
A) 3345
B) 3320
C) 3345
D) 3320
**Answer: B**
**96. What is the output?**
```java
System.out.println(2 * 3 + "4" + 5 * 6);
```
A) 6456
B) 6430
C) 6456
D) 6430
**Answer: B**
**97. What is the output?**
```java
System.out.println(Math.random() < 1);
```
A) true
B) false
C) 0
D) 1
**Answer: A**
**98. What is the output?**
```java
System.out.println(10 > 9 > 8);
```
A) true
B) false
C) Error
D) 1
**Answer: C**
**99. What is the output?**
```java
int a = 10;
System.out.println(a << 1);
```
A) 10
B) 20
C) 5
D) 11
**Answer: B**
**100. What is the output?**
```java
System.out.println(10 & 6);
```
A) 10
B) 6
C) 2
D) 4
**Answer: C**