NPTEL Programming in Java Week 1 Assignment Answers 2024
1. Which of the following is not a valid comment in Java?
a. /** comment */
b. /* comment */
c. /* comment /
d. // comment
Answer :- c
2. What is the output of the following code?
public class Main {
public static void main(String[] args) {
String str1 = "NPTEL";
String str2 = "java";
int a = 20;
int b = 24;
System.out.println(str1 + a + b); // Statement 1
System.out.println(a + b + str2); // Statement 2
}
}
a. NPTEL2024
44java
b. NPTEL44
44java
c. NPTEL2024
2024java
d. NPTEL44
2024java
Answer :- a
3. Which of the following is used to find and fix bugs in the Java programs?
a. JVM
b. JRE
c. JDK
d. JDB
Answer :- For Answers Click Here
4. What is the value returned by the method f() defined below ?
public static int f(int x, int y){return (x>y) ? y : x;}
a. The sum of x and y, that is, x + y.
b. The difference of x and y, that is, x – y.
c. The maximum of x and y, that is, the larger value of x and y.
d. The minimum of x and y, that is, the smaller value of x and y.
Answer :- For Answers Click Here
5. Consider the following program. What will be the output of the program if it is executed?
public class Question {
public static void main(String args[]) {
int f = 0, g = 1;
for (int i = 0; i <= 5; i++) {
System.out.println(f);
f = f + g;
g = f - g;
}
}
}
a. Print first six even numbers.
b. Print first six odd numbers.
c. Print first six prime numbers.
d. Print first six Fibonacci numbers.
Answer :-
6. Which program is used to compile Java source code into bytecode?
a. javap
b. javac
c. java
d. javad
Answer :-
7. Consider the following program.
public class Question {
public static void main(String[] args) {
int x = 5;
x *= (2 + 8);
System.out.println(x);
}
}
a. 50
b. 10
c. Compiler error
d. 5
Answer :- For Answers Click Here
8. What is the incorrect statement about bytecode?
a. Java when compiles the source code, it converts it to bytecode.
b. JVM (Java Virtual Machine) is an interpreter of bytecode.
c. Bytecode is not portable and it needs to be compiled separately for each platform.
d. JVM offers a protected environment which helps in enhanced safety for the system.
Answer :-
9. In Java, what is the role of the public static void main(String[] args) method?
a. Initialization method
b. Execution entry point
c. Constructor
d. Destructor
Answer :-
10. What is the purpose of the break statement in Java?
a. To terminate the program
b. To exit a loop or switch statement
c. To skip the next iteration of a loop
d. To return a value from a method
Answer :- For Answers Click Here