I O T M A: AVA Rogramming
I O T M A: AVA Rogramming
I O T M A: AVA Rogramming
A. Hello
B. Bye
Syntax: How to Declare a Variable
C. Error
D. All of these
13. Is string mutable in Java? Answer: B) Bye
A. Yes
Explanation: The argument of if statement
B. No should be Boolean type. By mistake if we are
trying to provide any other data type then we
Answer: B) No
will get compile-time error saying incompatible
Explanation: String is an example of an types. Here the argument is of int type,
immutable type. A String object always therefore we will get compile time error saying
represents the same string. StringBuilder is an error: incompatible types: int cannot be
example of a mutable type. converted to Boolean
15. What will be the output of following Java 17. Which type of casting is lossy in Java?
code?
A. Widening typecasting
public class Main { B. Narrowing typecasting
public static void main(String[]
args) {
C. Manual typecasting
String str = "Hello";
str = "Bye";
System.out.println(str); D. All of these
Answer: B) Narrowing typecasting
public class Main {
public static void main(String arg[]) {
Explanation: In the case of Narrowing Type
int i;
Casting, the higher data types (having larger for (i = 1; i <= 12; i += 2) {
size) are converted into lower data types if (i == 8) {
(having smaller size). Hence there is the loss of System.out.println(i);
data. break;
}
}
18. Which of the following can be declared as }
final in java? }
A. Class
A. 1
B. Method B. No output
C. Variable C. 8
D. 1357911
D. All of these
Answer: B) No output
Answer: D) All of these
Explanation: The final modifier for finalizing Explanation: ~
the implementations of classes, methods, and
variables. The main purpose of using a class
being declared as final is to prevent the class 21. Can the Java program accept input from the
from being subclassed. If a class is marked as command line?
final then no class can inherit any feature from
A. Yes, using command-line arguments
the final class.
B. Yes, by access command prompt
C. No
19. The break statement in Java is used to ___.
D. None of these
A. Terminates from the loop immediately
Answer: A) Yes, using command-line arguments
B. Terminates from the program
immediately Explanation: Can Java program accept input
from command line?
C. Skips the current iteration
The java command-line argument is an
D. All of these
argument i.e. passed at the time of running the
Answer: A) Terminates from the loop java program. The arguments passed from the
immediately console can be received in the java program
and it can be used as an input.
Explanation: The break statement in Java
terminates the loop immediately, and the
control of the program moves to the next
statement following the loop. It is almost
always used with decision-making statements 22. Object in java are ___.
(Java if...else Statement).
A. Classes
B. References
C. Iterators
D. None of these
20. What will be the output of following Java
code? Answer: B) References
Explanation: A Java object is a member (also 25. 'this' keyword in java is ___.
called an instance) of a Java class. Each object
A. Used to hold the reference of the
has an identity, a behavior and a state. The
current object
state of an object is stored in fields (variables),
while methods (functions) display the object's B. Holds object value
behavior. Objects are created at runtime from
templates, which are also known as classes. C. Used to create a new instance
A. C:\Program Files\Java\jdk1.8.0_131\
bin\file_name.txt 30. Which statement is correct for private member
B. C:\Program Files\Java\file_name.txt in Java?
C. C:\Program Files\Java\jdk1.8.0_131\ A. Access outside the class is allowed
file_name.txt
D. C:\Program Files\Java\jdk1.8.0_131\ B. Any class can access
bin\File Handling\file_name.txt
C. Declared using private keyword
Answer: A) C:\Program Files\Java\jdk1.8.0_131\
D. All of these
bin\file_name.txt
Answer: C) Declared using private keyword
Explanation: The private members are
Explanation: ~
declared using the private keyword.
28. What will be the output of following Java 31. What are packages in Java?
code? A. Methods of a friend class
B. Methods of the main class
public class Main {
public static void main(String[] args) { C. Way to encapsulate a group of classes,
StringBuffer sb = new StringBuffer("include"); sub-packages, and interface
sb.append("help");
System.out.println(sb); D. All of these
} Answer: C) Way to encapsulate a group of
} classes, sub-packages, and interface
Explanation: ava packages are the ways to
A. Error
B. include encapsulate a group of classes, sub-packages,
C. help and interface.
D. Includehelp
Explanation: Equal to operator has least Answer: (A) Bytecode is executed by the JVM.
precedence. Brackets () have highest Explanation: Bytecode is executed by JVM is
precedence. Division operator, /, has higher the correct answer.
precedence than multiplication operator.
Addition operator, +, and subtraction operator The output of the Java compiler is bytecode,
have equal precedence. which leads to the security and portability of
the Java code. It is a highly developed set of
instructions that are designed to be executed by
40. What will be the output of the following Java the Java runtime system known as Java
program? Virtual Machine (JVM). The Java programs
executed by the JVM that makes the code
class Output portable and secure. Because JVM prevents the
{ code from generating its side effects. The Java
code is portable, as the same byte code can run
public static void main(String args[]) on any platform.
{
int p = 1; 42. Which of the following is not a Java features?
int q = 2; A. Dynamic
int r = 3; B. Architecture Neutral
p |= 4; C. Use of pointers
q >>= 1; D. Object-oriented
r <<= 1; Answer: (C) Use of pointers
p ^= r; Explanation: Pointers is not a Java feature.
Java provides an efficient abstraction layer for
System.out.println(q + ” ” + q + ” ” + r);
developing without using a pointer in Java.
} Features of Java Programming are Portable,
Architectural Neutral, Object-Oriented,
Robust, Secure, Dynamic and Extensible, etc.
46. Which component is used to compile, debug
and execute the java programs?
43. _____ is used to find and fix bugs in the Java A. JRE
programs.
B. JIT
A. JVM
C. JDK
B. JRE
D. JVM
C. JDK
Answer: C
D. JDB
Explanation: JDK is a core component of Java
Answer: (D) JDB Environment and provides all the tools,
executables and binaries required to compile,
Explanation: The Java Debugger also known
debug and execute a Java Program.
as JDB is used to find and fix bugs in the Java
program.
1. class variable_scope
2. {
3. public static void main(String
args[])
4. {
5. int x;
6. x = 5;
7. {
8. int y = 6;
9. System.out.print(x + " " + y);
10. }
11. System.out.println(x + " " + y);
12. }
13. }
A. Compilation error
B. Runtime error
C. 5 6 5 6
D. 5 6 5
Answer: A
Explanation: Second print statement doesn’t
have access to y , scope y was limited to the
block defined after initialization of x.