Programming in Java | NPTEL 2023 | Week 2 quiz solutions

This set of MCQ(multiple choice questions) focuses on the Programming in Java NPTEL 2023 Week 2 Quiz Solutions.

Course layout (Answers Link)

Answers COMING SOON! Kindly Wait!

NOTE: You can check your answer immediately by clicking show answer button. Programming in Java NPTEL 2023 Week 2 Quiz Solutions” contains 10 questions.

Now, start attempting the quiz.

Programming in Java NPTEL 2022 Week 2 Quiz Solutions

Q1. Consider the following code segment:

1 class Question{
2   public static void main(String args){
3       System.out.print("Welcome to NPTEL");
4   }
5 }

Identify the line number(s) where there is/are error(s) in the above code.

a) 1
b) 2
c) 3
d) 4 and 5

Answer: b) 2

Q2. Consider the following code segment:

1  class Question{
2      public static void main(String[] param){
3          System.out.print("Welcome to NPTEL");}}
4      }
5  }

Identify the line number(s) where there is error in the above code.

a) 1
b) 2
c) 3
d) 4 and 5

Answer: d) 4 and 5

Q3. Consider the following code segment:

class Question{
    public static void main(String args[]){
        for(int n=1; n<=10; n++){
            System.out.print(n + " ");
        }
    }
}

Select the correct output description for the above code.

a) Prints first n natural numbers in a single line.
b) Prints first n natural numbers, one number in a single line.
c) Prints first 10 natural numbers in a single line.
d) Prints first 10 natural numbers in a single line with no spaces.

Answer: c) Prints first 10 natural numbers in a single line.

Q4. Consider the following code segment:

1 class Question{
2    public static void main(String args[]){
3        for(int n=1; n<=100; n++){
4            System.out.print(n + " ");
5        }
6    }
7 }

Modify the above code such that it prints all the even numbers till 100.

a) Replace line 3 with for(int n=2; n<=100; n++)
b) Replace line 3 with for(int n=1; n<=100; n+=2){
c) Replace line 4 with System.out.print(++n + ” “);
d) Both option a and c

Answer: c)

Q5. What will be the output of the above program?

a) 22221018
b) 22222018
c) 22101018
d) 22221218

Answer: b) 22222018

Q6. How to correct the above code segment?

a) Change line 4 as x = (short) (x * 5);
b) Change line 4 as x = (short) x * 5;
c) Change line 4 as x = (short) x * (short) 5;
d) Change line 4 as (short) x = x * 5;

Answer: a)

Q7. What is the output of the following program?

a) 210
b) 120
c) 012
d) 000

Answer: d) 000

Q8. Which of the following option is the output of the above program?

a) java
b) npteljava
c) nptel java
d) nptel

Answer: d) nptel

Q9. What is the output of the following program?

a) 60
b) 117
c) 33
d) Compilation error

Answer: d) Compilation error

Q10. What will be the output of the program if it is executed?

a) 50
b) 10
c) Compiler error
d) 5

Answer: a) 50

Programming in Java NPTEL 2023 Week 2 Quiz Solutions

Q1. Following is a program given for this question.
What will be the output of the above program?

a) 22221010
b) 12222101
c) 22101010
d) 22221012

Answer: a) 22221010

Q2. When an array is passed to a method, what value does the method receive?

a) Reference of the array
b) Copy of the array
c) First element in the array
d) Length of the array

Answer: a) Reference of the array

Q3. What will be the output of the above program?

a) 28
b) -29
c) 30
d) -31

Answer: c) 30

Q4. 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

Answer: a) 32 and 64

Q5. 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

Answer: d) int to long

Q6. Consider the following program and identify the output.

a) 5
b) 10
c) 50
d) Compilation error

Answer: d) Compilation error

Q7. Which of the following is a valid declaration of an object of class say, Student?

a) Student obj = new Student;
b) Student obj = new Student();
c) obj = new Student();
d) new Student obj;

Answer: b) Student obj = new Student();

Q8. What is the output of the following program?

a) 210
b) 120
c) 012
d) 201

Answer: c) 012

Q9. Which of the following option is the output of the above program?

a) java
b) npteljava
c) nptel java
d) nptel

Answer: d) nptel

Q10. What is the output of the following program?

a) 60
b) 3011
c) 33
d) Compilation error

Answer: d) Compilation error

Programming in Java NPTEL 2022 Week 2 Quiz Solutions

Q1. What is the output of the following program?

public class Main {
    public static void main(String args[]) {
           char a = '8';
           int b = 010;
           System.out.println(a+b);
    }
}

a) 88
b) 8010
c) 64
d) 810

Answer: c) 64

Q2. Which of the following is generate API documentation in HTML format from Java source code?

a) javac
b) javadoc
c) javap
d) java

Answer: b) javadoc

Q3. Following is a program given for this question.

public class Main{
     public static void main(String[] args) {
        char[] copyFrom = { 'j', 'a', 'n', 'n', 'p', 't', 'e', 'l', 'j', 'a', 'v', 'a',};
        char[] copyTo = new char[9];

        System.arraycopy(copyFrom, 3, copyTo, 0, 9);
     }
}

What will be the output of the above program?

a) javanptel
b) npteljava
c) janjavanptel
d) jannpteljava

Answer: b) npteljava

Q4. What will happen during the execution of the following code for the command line input?

public class Question {
     public static void main (String[] args) {
         for (String s: args) {
             System.out.println(s+args[0]);
         }
     }
}

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

Answer: b), c)

Q5. 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.

Answer: d) println() prints and then appends a line break.

Programming in Java NPTEL 2022 Week 2 quiz Solutions

Q6. What was the initial name of Java when it was first developed for embedded systems?

a) Greentalk
b) Oak
c) Java
d) Javac

Answer: a) Greentalk

Q7. Which of the following is a valid declaration of an object of class, say Foo?

a) Foo obj = new Foo;
b) obj = new Foo();
c) Foo obj = new Foo();
d) new Foo obj;

Answer: c) Foo obj = new Foo();

Programming in Java NPTEL 2022 Week 2 Quiz solutions

Q8. Following is a program given for this question.

public class Question
{
     public static void main(String[] args) {
         
       boolean m = Integer.valueOf(0).equals(Long.valueOf(1));
       System.out.println(m);
    }
}

What will be the output of the above program?

a) 0
b) 1
c) false
d) true

Answer: c) false

Q9. Which of the following can be used to take input from user during the execution of a program?

a) Using the string array provided as a parameter to the main method.
b) getText() method can be used to get user input from the command line.
c) Scanner class can be used by passing the predefined object System.in
d) Once the execution starts, there is no way to provide user input.

Answer: c) Scanner class can be used by passing the predefined object System.in

Q10. What is the output of the following program?

public class Question
{
     public static void main(String[] args) {
         
          int i = 10;
          int n = i++%2;
          int m = ++i%7;
          System.out.println(i+n+m);
     }
}

a) 14
b) 12
c) 15
d) 17

Answer: d) 17

<< Pre- Programming in Java Week 1 Assignment Solutions

>> Next- Programming in Java Week 3 Assignment Solutions


DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.

Nptel – Deep Learning assignment solutions

Social Networks nptel assignment answers

NPTEL answers: Programming in Modern C++

For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.

2 thoughts on “Programming in Java | NPTEL 2023 | Week 2 quiz solutions”

Leave a Comment

Your email address will not be published. Required fields are marked *