0% found this document useful (0 votes)
15 views

Programming in Java - - Unit 5 - Week 2 _

The document outlines the second week of the Programming in Java course offered by NPTEL, detailing assignment submissions, quiz questions, and correct answers related to Java class declarations, constructors, and methods. It includes multiple-choice questions with accepted answers, focusing on key concepts such as the 'this' keyword, constructor overloading, and input handling using the Scanner class. The assignment was due on August 7, 2024, and the document reflects a completed submission on August 6, 2024.

Uploaded by

kalidasji210
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Programming in Java - - Unit 5 - Week 2 _

The document outlines the second week of the Programming in Java course offered by NPTEL, detailing assignment submissions, quiz questions, and correct answers related to Java class declarations, constructors, and methods. It includes multiple-choice questions with accepted answers, focusing on key concepts such as the 'this' keyword, constructor overloading, and input handling using the Scanner class. The assignment was due on August 7, 2024, and the document reflects a completed submission on August 6, 2024.

Uploaded by

kalidasji210
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

13/11/2024, 15:26 Programming in Java - - Unit 5 - Week 2 :

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Programming in Java (course)

Course Week 02: Assignment 02


outline The due date for submitting this assignment has passed.
Due on 2024-08-07, 23:59 IST.
About
NPTEL ()
Assignment submitted on 2024-08-06, 22:30 IST
How does an 1) Which of the following is the correct way to declare a class in Java? 1 point
NPTEL
online a. public class MyClass {}
course b. class MyClass[] {}
work? ()
c. public MyClass class {}

Week 0 : () d. MyClass public class {}


Yes, the answer is correct.
Week 1 : () Score: 1
Accepted Answers:
a. public class MyClass {}
Week 2 : ()

Lecture 06 : 2) What is the purpose of a constructor in a class? 1 point


Demonstration
-II (unit? a. To destroy objects of the class
unit=26&lesso b. To create static methods
n=27)
c. To implement inheritance
Lecture 07 : d. To initialize objects of the class
Encapsulation
(unit? Yes, the answer is correct.
Score: 1
unit=26&lesso
n=28) Accepted Answers:
d. To initialize objects of the class
Lecture 08 :
Demonstration
3) Which keyword is used in Java to refer to the current object? 1 point
-III (unit?
unit=26&lesso a. that
n=29)
b. self

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=26&assessment=390 1/4
13/11/2024, 15:26 Programming in Java - - Unit 5 - Week 2 :

Lecture 09 : c. current
Java
d. this
Programming
Insights (unit? Yes, the answer is correct.
unit=26&lesso Score: 1
n=30) Accepted Answers:
d. this
Lecture 10 :
Demonstration 4) Consider the following code snippet. What will be the output? 1 point
-IV (unit?
unit=26&lesso
n=31) class NPTEL_W2 {
Week 02 : int x;
Programming
Assignment 1
(/noc24_cs105 NPTEL_W2(int x) {
/progassignme
this.x = x;
nt?name=366)
}
Week 02 :
Programming
Assignment 2
void printX() {
(/noc24_cs105
/progassignme System.out.println(this.x);
nt?name=367)
}
Week 02 :
Programming
Assignment 3 public static void main(String[] args) {
(/noc24_cs105 NPTEL_W2 obj = new NPTEL_W2(10);
/progassignme
nt?name=368)
obj.printX();
}
Week 02 :
Programming }
Assignment 4
(/noc24_cs105
a. 0
/progassignme
nt?name=369) b. 10
c. Compilation error
Week 02 :
Programming d. Runtime error
Assignment 5
Yes, the answer is correct.
(/noc24_cs105 Score: 1
/progassignme Accepted Answers:
nt?name=370) b. 10
Quiz: Week
02: 5) Which of the following demonstrates constructor overloading in Java? 1 point
Assignment
02 a. Defining multiple constructors in a class with different parameter lists
(assessment? b. Defining multiple methods in a class with the same name
name=390)
c. Defining a constructor in a subclass
Week 02 : d. Using the super keyword
Assignment
Solution (unit? Yes, the answer is correct.

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=26&assessment=390 2/4
13/11/2024, 15:26 Programming in Java - - Unit 5 - Week 2 :

unit=26&lesso Score: 1
n=431) Accepted Answers:
a. Defining multiple constructors in a class with different parameter lists
Week 3 : ()
6) What is the purpose of the this keyword in the context of avoiding name space 1 point
Week 4 : () collision?

a. To call another constructor in the same class


Week 5 : ()
b. To refer to the current object

Week 6 : () c. To differentiate between instance variables and parameters with the same name
d. To import another class
Week 7 : ()
Yes, the answer is correct.
Score: 1
Week 8 : () Accepted Answers:
c. To differentiate between instance variables and parameters with the same name
Week 9 : ()
7) Which of the following is the correct signature of the main method in Java? 1 point
Week 10 : ()
a. public void main(String[] args)
Week 11 : () b. public static void main(String[] args)
c. public static void main()
Week 12 : ()
d. public main(String[] args)

Books () Yes, the answer is correct.


Score: 1
Accepted Answers:
Text
b. public static void main(String[] args)
Transcripts
()
8) Which class is used in Java to take runtime data input from the user? 1 point

a. BufferReader
b. UserInputStreamReader
c. Scanner
d. DataInputStreamReader

Yes, the answer is correct.


Score: 1
Accepted Answers:
c. Scanner

9) What is the output of the following Java code snippet? (\n in output is to be 1 point
assumed to be the new line character)

public class Main {

public static void main(String[] args) {


System.out.print("Hello ");
System.out.println("World");
System.out.printf("Number: %d", 10);
}

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=26&assessment=390 3/4
13/11/2024, 15:26 Programming in Java - - Unit 5 - Week 2 :

a. Hello World\nNumber: 10
b. Hello WorldNumber: 10
c. Hello \nWorld\nNumber: 10
d. Hello World\nNumber: 10\n

Yes, the answer is correct.


Score: 1
Accepted Answers:
a. Hello World\nNumber: 10

10) How do you read a line of text from the console using the Scanner class in Java? 1 point

a. scanner.readLine()
b. scanner.nextLine()
c. scanner.getLine()
d. scanner.fetchLine()

Yes, the answer is correct.


Score: 1
Accepted Answers:
b. scanner.nextLine()

https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=26&assessment=390 4/4

You might also like