Programming in Java - - Unit 5 - Week 2 _
Programming in Java - - Unit 5 - Week 2 _
(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)
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?
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)
a. BufferReader
b. UserInputStreamReader
c. Scanner
d. DataInputStreamReader
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)
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
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()
https://onlinecourses.nptel.ac.in/noc24_cs105/unit?unit=26&assessment=390 4/4