Assignment - 2 Solution
Assignment - 2 Solution
PROGRAMMING IN JAVA
Assignment 2
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________
QUESTION 1:
Following is a program given for this question.
Detailed Solution:
Since, int[2] numeral value have 0 in leading, therefore, it's taken as octal base (8). So, it's
corresponding decimal value is (2 × 80) + (1 × 81) = 10.
QUESTION 2:
When an array is passed to a method, what value does the method receive?
Correct Answer: a
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Detailed Solution:
Reference of the array is passed to a method in Java.
____________________________________________________________________________
QUESTION 3:
Following is a program given for this question.
Correct Answer: c
Detailed Solution:
The increment operator ++ works here in the normal scenario as there is nor assignment
operator. So, it will not give any difference between ++x and x++.
QUESTION 4:
How many bits are needed for float and double in Java, respectively?
a. 32 and 64
b. 32 and 32
c. 64 and 64
d. 64 and 32
Correct Answer: a
Detailed Solution:
QUESTION 5:
Which of the following is a valid automatic type conversion in Java?
a. short to byte
b. float to long
c. int to short
d. int to long
Correct Answer: d
Detailed Solution:
Automatic type conversation is possible in the following sequence (reverse is not possible):
QUESTION 6:
Consider the following program and identify the output.
a. 5
b. 10
c. 50
d. Compilation error
Correct Answer: d
Detailed Solution:
Compilation Error in “x = x * 5;”. This is due to lossy conversion from int to short. It works
if the type casting is followed, for example, x = (short) ( x * 5);
QUESTION 7:
Which of the following is a valid declaration of an object of class say, Student?
Correct Answer: b
Detailed Solution:
When an object is to be declared it needs to be instantiated, hence the correct syntax of declaring
an object is (b).
______________________________________________________________________________
QUESTION 8:
What is the output of the following program?
a. 210
b. 120
c. 012
d. 201
Correct Answer: c
Detailed Solution:
The output after execution is 012.
QUESTION 9:
Consider the following piece of code.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Correct Answer: d
Detailed Solution:
The output can be checked by execution.
QUESTION 10:
What is the output of the following program?
a. 60
b. 3011
c. 33
d. Compilation error
Correct Answer: d
Detailed Solution:
There is a compilation error due to incorrect syntax in the statement public void static
main(String args[]); it should be public static void main(String args[]){
******