Week 01 Assignment
Week 01 Assignment
Week 01 Assignment
PROGRAMMING IN JAVA
Assignment 1
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________
QUESTION 1:
Which of the following cannot be used for a variable name in Java?
a. identifier
b. case
c. malloc
d. calloc
Correct Answer: b
Detailed Solution:
case is a reserved keyword in Java, which cannot be used for naming a variable or class.
____________________________________________________________________________
QUESTION 2:
Which of the following is an incorrect array declaration?
Correct Answer: c
Detailed Solution:
In the left hand side, it is a declaration for two-dimensional array, whereas at the right side it uses
new operator to allocate a memory for a one-dimensional array.
____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 3:
When you compile a program written in the Java programming language, the compiler
converts the human-readable source file into platform-independent code that a Java Virtual
Machine can understand. What is this platform-independent code called?
a. Source code
b. Bytecode
c. Machinecode
d. Opcode
Correct Answer: b
Detailed Solution:
Byte code is an intermediate code between source code and machine code that is executed by an
interpreter such as JVM. e.g., Java class files.
________________________________________________________________________
QUESTION 4:
Which of the following is/are TRUE regarding the string array provided as a parameter to
the main method in Java?
Correct Answer: a
Detailed Solution:
In Java, the function of the string array provided in the main method is to get the command line
arguments provided by the user during the execution of the program. This is just like any other
string array and hence, its name can be set anything. Since, the command line values are passed
to the main method, this can be used anywhere in the program. Users are allowed to put multiple
command line arguments one after another using spaces in between.
________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 5:
Consider the following program.
QUESTION 6:
In the following, some options are given. You have to choose the correct option for the argument
in System.out.print() function to print the second and the last characters in the array nptel.
a. nptel[nptel.length-1] + nptel[1]
b. nptel[1] + nptel[nptel.length-1]
c. "" + nptel[1] + nptel[nptel.length-1]
d. "" + nptel[nptel.length-1] + nptel[1]
Correct Answer: c
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
QUESTION 7:
a. 20
b. 25
c. 32
d. 31
Correct Answer: a
Detailed Solution:
First the value of i will be decremented and then multiplication is performed and the result will
be printed.
QUESTION 8:
Which of the following is used to find and fix bugs in the Java programs?
a. JVM
b. JRE
c. JDK
d. JDB
Correct Answer: d
Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
The Java Debugger (JDB or jdb) is a command-line java debugger that debugs the java class.
QUESTION 9:
Which of the following is/are non-primitive data type(s) in Java?
a. int
b. String
c. Array
d. double
Detailed Solution:
A String in Java is actually a non-primitive data type, because it refers to an object.
QUESTION 10:
Which of the following features are common in both Java and C++?
Detailed Solution:
C++ supports multiple inheritances whereas Java does not.
******