Week-01Assignmentupdate Java PDF
Week-01Assignmentupdate Java PDF
PROGRAMMING IN JAVA
Assignment 1
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10
______________________________________________________________________________
QUESTION 1:
Which of the following code fragment(s) is/are true?
Detailed Solution:
The modifiers public and static can be written in either order (public static or static public). You
can name the argument anything you want, but most programmers choose "args" or "argv".
NPTEL Online Certification Courses
Indian Institute of Technology
_________________________________________________________________________
QUESTION 2:
Which of the following is not a valid comment?
a. /** comment */
b. /* comment */
c. /* comment
d. // comment
Correct Answer: c
Detailed Solution:
Option c : /* comment .
This is not valid comment statement
___________________________________________________________________________
QUESTION 3:
Which of the following is not an object-oriented programming paradigm?
a. Encapsulation
b. Inheritance
c. Polymorphism
d. Dynamic memory allocation
Correct Answer: d
Detailed Solution:
Dynamic memory allocation is a memory allocation strategy and not a programming paradigm.
______________________________________________________________________________
QUESTION 4:
Which of the following is not a correct statement?
Correct Answer: a
NPTEL Online Certification Courses
Indian Institute of Technology
Detailed Solution:
Array can be initialized using both new and comma separated expressions surrounded by curly
braces example : int a [ ] = new int[5]; int [] a; a = new int [10]; and int a [] = { 0, 1, 2, 3, 4};
______________________________________________________________________________
QUESTION 5:
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 6:
Consider the following program.
______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology
QUESTION 7:
Why an array is called “homogeneous collection of data“ in Java?
Correct Answer: c
Detailed Solution: Homogeneous data means a data of same type. And, array can hold only one
type of data i.e. you cannot have an array with items of multiple data type.
_________________________________________________________________________
QUESTION 8:
Which of the following can be used for a variable name in Java?
a. boolean
b. final
c. finally
d. calloc
Correct Answer: d
Detailed Solution:
final, boolean, finally are reserved keyword in Java, which cannot be used for naming a variable
or class.
______________________________________________________________
QUESTION 9:
System.out.println(a+b+str2); //Statement 2
}
}
NPTEL Online Certification Courses
Indian Institute of Technology
Detailed Solution:
+ (plus) operator is overloaded in java.
QUESTION 10:
What will be the output of the following code?
public class Question{
public static void main(String args[]){
if(true){
System.out.print("Welcome");
}
if(1==1){
System.out.print(" to ");
}
if(1){
System.out.print("NPTEL");
}
}
}
a. Welcome
b. Welcome to
c. Welcome to NPTEL
d. Compilation Error
Correct Answer: d
Detailed Solution:
___________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology