0% found this document useful (0 votes)
517 views

JAVA MCQ (Answers) - 2

The document contains questions and answers related to Java programming concepts like data types, operators, OOPs concepts, methods, loops etc. It discusses the range of short data type, output of code snippets involving conversions between data types, necessary conditions for automatic type conversion, data type of expressions containing multiple data types, character representation in Java and more.

Uploaded by

Sri Sri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
517 views

JAVA MCQ (Answers) - 2

The document contains questions and answers related to Java programming concepts like data types, operators, OOPs concepts, methods, loops etc. It discusses the range of short data type, output of code snippets involving conversions between data types, necessary conditions for automatic type conversion, data type of expressions containing multiple data types, character representation in Java and more.

Uploaded by

Sri Sri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

What is the range of data type short in Java?

a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
View Answer
Answer:b

What is the output of this program?


class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
View Answer
Answer:b

Which of these is necessary condition for automatic type conversion in Java?


a) The destination type is smaller than source type.
b) The destination type is larger than source type.
c) The destination type can be larger or smaller than source type.
d) None of the mentioned
View Answer
Answer:b
Explanation:None.
If an expression contains double, int, float, long, then whole expression will promoted into which of these data
types?
a) long
b) int
c) double
d) float
View Answer
Answer: c

Java uses ___ to represent characters


a) ASCII code
b) Unicode
c) Byte code
d) None of the above
Answer b
Which one is not supported by OOP?
a) Abstraction
b) Polymorphism
c) Encapsulation
d) Global variables
Answer d
The java compiler
a) creates executable
b) translates java source code to byte code
c) creates classes
d) produces java Interpreter

Answer b

The new operator


a) returns a pointer to a variable
b) creates a variable called new
c) obtains memory for a new variable
d) tells how much memory is available

Answer c
Command to execute a compiled java program is :
a) javac
b) java
c) run
d) execute

Answer b

Modulus operator, %, can be applied to which of these?


a) Integers
b) Floating – point numbers
c) Both Integers and floating – point numbers.
d) None of the mentioned
Answer:c
What is the output of this program?
1. class increment {
2. public static void main(String args[])
3. {
4. double var1 = 1 + 5;
5. double var2 = var1 / 4;
6. int var3 = 1 + 5;
7. int var4 = var3 / 4;
8. System.out.print(var2 + " " + var4);
9.  
10. }
11. }
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0

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

What is the output of this program?


1. class box {
2. int width;
3. int height;
4. int length;
5. }
6. class mainclass {
7. public static void main(String args[])
8. {
9. box obj1 = new box();
10. box obj2 = new box();
11. obj1.height = 1;
12. obj1.length = 2;
13. obj1.width = 1;
14. obj2 = obj1;
15. System.out.println(obj2.height);
16. }
17. }
a) 1
b) 2
c) Runtime error
d) Garbage value
View Answer
Answer: a
What is the process of defining more than one method in a class differentiated by method signature?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
Answer:b

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

. Which data type value is returned by all transcendental math functions?


a) int
b) float
c) double
d) long
View Answer

Answer: c

Which of these values can a boolean variable contain?


a) True & False
b) 0 & 1
c) Any integer value
d) true
View Answer

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

You might also like