Programming In Java | Week 2
Session: JAN-APR 2024
Course name: Programming In Java
Course Link: Click Here
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q1. In Java programming an object can take many forms. This feature is called _______.
a. Abstraction
b. Polymorphism
c. Encapsulation
d. Inheritance
Answer: b. Polymorphism
Q2. Which of the following is a valid declaration of an object of class, say NPTEL?
a. NPTEL obj = new NPTEL();
b. NPTEL obj = new NPTEL;
c. obj = new NPTEL();
d. new NPTEL obj;
Answer: a. NPTEL obj = new NPTEL();
Q3. A default constructor_______________________.
a. has no arguments
b. has no return type
c. has one argument but no return type
d. has two arguments
Answer: a. has no arguments
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q4. A top-level class may have which one of the following access modifiers?
a. package
b. private
c. protected
d. public
Answer: d. public
Q5. Integer in Java is a\an __________.
a. Adapter class
b. Inner class
c. Not a class
d. Wrapper class
Answer: d. Wrapper class
Q6. What is true about the new operator?
a. returns a pointer to a variable
b. creates a variable called new
c. obtains memory for a new variable
d. tells how much memory is available
Answer: c. obtains memory for a new variable
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q7. Which one is not supported by OOP?
a. Abstraction
b. Polymorphism
c. Encapsulation
d. Global variables
Answer: d. Global variables
Q8. Which of the following modifiers can be used to disallow a method from being overridden?
a. final
b. transient
c. volatile
d. static
Answer: a. final
Q9. Consider the following code segment
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
Q10. Which of the following is TRUE about print() and println() methods?
a. print() prints in a single line only and multiple lines cannot be printed in any way.
b. println() prints and then appends a line break.
c. println() prints in a single line only and multiple lines cannot be printed.
d. print() prints and then appends a line break.
Answer: b. println() prints and then appends a line break.
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
More Weeks of Programming In Java: Click here
More Nptel Courses: https://progiez.com/nptel-assignment-answers
Session: JULY-DEC 2023
Course Name: Programming In Java
Course Link: Click Here
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Programming Assignment
Question 1
Complete the code segment to call the method print() of class Student first and then call print() method of class School.
Solution:
Student student = new Student();
student.print();
School school = new School();
school.print();
Question 2
Complete the code segment to call the method print() of class given class Printer to print the following.
——————————–
Hi! I am class STUDENT
Hi! I class SCHOOL.
——————————–
Solution:
Printer p = new Printer();
p.print("Hi! I am class STUDENT");
p.print();
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Question 3
Complete the code segment to call print() method of class Question by creating a method named ‘studentMethod()’.
Solution:
void studentMethod(){
print(this);
}
Question 4
Complete the code segment to call default constructor first and then any other constructor in the class.
Solution:
class Answer{
Answer(){
System.out.println("You got nothing.");
}
Answer(int marks, String type){
this();
System.out.print("You got "+marks+" for an "+ type);
}
}
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Question 5
Complete the code segment to debug / complete the program which is intended to print ‘NPTEL JAVA’.
Solution:
String nptel,space,java;
nptel="NPTEL";
space=" ";
java="JAVA";
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
More Weeks of Programming In Java: Click here
More Nptel Courses: Click here
Session: JAN-APR 2023
Course Name: Programming in Java
Course Link: Click Here
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Week 3: Click Here
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.
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q3. Following is a program given for this question.
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
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
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
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
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
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q9. Consider the following piece of code.
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
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Programming In Java Programming Assignment Solution
Question 1
Complete the code segment to call the method print() of class School first and then call print() method of class Student.
Solution:
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Question 2
Complete the code segment to call the method print() of class given class Printer to print the following.
——————————–
Hi! I am class SCHOOL
Hi! I class STUDENT.
——————————–
Solution:
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Question 3
Complete the code segment tocall print() method of class Question by creating a method named ‘student()’.
Solution:
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Question 4
Complete the code segment to call default constructor first and then any other constructor in the class.
Solution:
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Question 5
Complete the code segment to debug / complete the program which is intended to print ‘NPTEL JAVA’.
Solution:
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
More Weeks of Programming In Java: Click Here
Session: JULY-DEC 2022
Q1. What is the output of the following program?
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.
What will be the output of the above program?
a) javanptel
b) npteljava
c) janjavanptel
d) jannpteljava
Answer: b) npteljava
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q4. What will happen during the execution of the following code for the command line input?
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.
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
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();
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q8. Following is a program given for this question.
What will be the output of the above program?
a) 0
b) 1
c) false
d) true
Answer: c) false
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
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?
a) 14
b) 12
c) 15
d) 17
Answer: d) 17
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Programming in Java NPTEL Week 2 Programming Assignment Solutions
Q1. Complete the code segment to call the method print() of class Student first and then call print() method of class School.
Sol:-
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q2. Complete the code segment to call the method print() of class given class Printer to print the following.
——————————–
Hi! I am class STUDENT
Hi! I class SCHOOL.
——————————–
Sol:-
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q3. Complete the code segment tocall print() method of class Question by creating a method named ‘studentMethod()’.
Sol:-
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q4. Complete the code segment to call default constructor first and then any other constructor in the class.
Sol:-
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
Q5. Complete the code segment to debug / complete the program which is intended to print ‘NPTEL JAVA’.
Sol:-
//Code
These are NPTEL Programming In Java Week 2 Assignment 2 Answers
The content uploaded on this website is for reference purposes only. Please do it yourself first. |