JAVA MCQ (Answers) - 2
JAVA MCQ (Answers) - 2
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
View Answer
Answer:b
Answer b
Answer c
Command to execute a compiled java program is :
a) javac
b) java
c) run
d) execute
Answer b
Answer:c
What is the output of this program?
1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. System.out.print(++g * 8);
6. }
7. }
a) 25
b) 24
c) 32
d) 33
Answer:c
Which of the following is a valid declaration of an object of class Box in Java?
a) Box obj = new Box();
b) Box obj = new Box;
c) obj = new Box();
d) new Box obj;
View Answer
Answer: a
Explanation: None.
4. Which of these operators is used to allocate memory for an object in Java?
a) malloc
b) alloc
c) new
d) give
View Answer
Answer: c
Which of the following is a method having same name as that of it’s class?
a) finalize
b) delete
c) class
d) constructor
Answer: d
Which method can be defined only once in a program?
a) main method
b) finalize method
c) static method
d) private method
Answer: a
What is the return type of Constructors?
a) int
b) float
c) void
d) None of the mentioned
Answer: d
Which of these jump statements can skip processing remainder of code in its body for a particular iteration?
a) break
b) return
c) exit
d) continue
Answer: d
What is the return type of a method that does not returns any value?
a) int
b) float
c) void
d) double
View Answer
Answer: c
What is true about constructor?
a) It can contain return type
b) It can take any number of parameters
c) It can have any non access modifiers
d) Constructor cannot throw exception
View Answer
Answer: b
What would be behaviour if constructor has a return type?
a) Compilation error
b) Runtime error
c) Compilation and runs successfully
d) Only String return type is allowed
View Answer
Answer: a
. Decrement operator, −−, decreases value of variable by what number?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: a
Which of these are selection statements in Java?
a) if()
b) for()
c) continue
d) break
View Answer
Answer:a
Which of the following loops will execute the body of loop even when condition controlling the loop is initially
false?
a) do-while
b) while
c) for
d) none of the mentioned
View Answer
Answer: a
The while loop repeats a set of code while the condition is not met?
a) True
b) False
View Answer
Answer: b
What is true about break?
a) Break stops the execution of entire program
b) Break halts the execution and forces the control out of the loop
c) Break forces the control out of the loop and starts the execution of next iteration.
d) Break halts the execution of the loop for certain time frame
View Answer
Answer: b
Which of the following is used with switch statement?
a) Continue
b) Exit
c) break
d) do
View Answer
Answer: c
An expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float
View Answer
Answer: a
Answer: c
Answer: a
Which of these operators is used to allocate memory to array variable in Java?
a) malloc
b) alloc
c) new
d) new malloc
View Answer
Answer: c
What is the process of defining a method in terms of itself, that is a method that calls itself?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
View Answer
Answer: d
What is the output of this program?
class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a, int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}
}
a) 5
b) 6
c) 7
d) 8
View Answer
Answer: c