Week 02 Assignment
Week 02 Assignment
Week 02 Assignment
PROGRAMMING IN JAVA
Assignment2
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________
QUESTION 1:
What is the output of the following program?
a. 88
b. 8010
c. 64
d. 810
Correct Answer: c
Detailed Solution:
The argument will take the + operator as the arithmetic addition on the ASCII values instead of
characters.
____________________________________________________________________________
QUESTION 2:
Which of the following is generate API documentation in HTML format from Java source
code?
a. javac
b. javadoc
c. javap
d. java
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Correct Answer: b
Detailed Solution:
javacdoc is generate API documentation in HTML format from Java source code.
___________________________________________________________________________
QUESTION 3:
Following is a program given for this question.
Correct Answer: b
Detailed Solution:
______________________________________________________________________
QUESTION 4:
What will happen during the execution of the following code for the command line input?
Consider the following input on command line and select the options with the correct output(s).
Input:
A: “jan java nptel”
B: 1 2 3
a. A : jannptel
javanptel
nptelnptel
b. A : jan java nptel jan java nptel
c. B : 11
21
31
d. B : 1 2 3 1
Correct Answer: b, c
Detailed Solution:
Java interpreted as a single argument, if the command line input is enclosing within quotation
marks.
____________________________________________________________________________
QUESTION 5:
Which of the following is/are TRUE about print() and println() methods?
a. print() prints in a single line only and multiple lines cannot be printed in any way.
b. print() prints and then appends a line break.
c. println() prints in a single line only and multiple lines cannot be printed.
d. println()prints and then appends a line break.
Correct Answer: d
Detailed Solution:
Method print() can be used to print in a single line only but multiple lines can be printed using
escape sequence ‘\n’. Similarly, println() prints in a single line only and multiple lines can be
printed using escape sequence ‘\n’. Method print() prints but does not appends a line break. So,
option (b) println() prints and then appends a line break is the only correct option.
____________________________________________________________________________
QUESTION 6:
What was the initial name of Java when it was first developed for embedded systems?
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
a. Greentalk
b. Oak
c. Java
d. Javac
Correct Answer: a
Detailed Solution:
Java was called "Greentalk" by James Gosling and the file extension was .gt and after that java
was called Oak and was developed as a part of the Green project.
______________________________________________________________________________
QUESTION 7:
Which of the following is a valid declaration of an object of class, say Foo?
Correct Answer: c
Detailed Solution:
Others are invalid declarations.
______________________________________________________________________________
QUESTION 8:
Following is a program given for this question.
boolean m=Integer.valueOf(0).equals(Long.valueOf(1));
System.out.println(m);
}
}
c. false
d. true
Correct Answer: c
Detailed Solution:
The two objects (the Integer and the Long) have different types.
______________________________________________________________________________
QUESTION 9:
Which of the following can be used to take input from user during the execution of a
program?
Correct Answer: c
Detailed Solution:
The easiest way to read input in a Java program during execution is by using the Scanner class in
java.util package. It can be used for obtaining the input of the primitive types like int, double, etc.
and strings. The argument values provided in the main method is only applicable when the
execution starts but during execution no value can be passed in that argument.
QUESTION 10:
int i = 10;
int n = i++%2;
int m = ++i%7;
System.out.println(i+n+m);
}
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
a. 14
b. 12
c. 15
d. 17
Correct Answer: d
____________________________________________________________________________
******