Need help with this week’s assignment? Get detailed and trusted solutions for Programming In Java Week 2 NPTEL Assignment Answers. Our expert-curated answers help you solve your assignments faster while deepening your conceptual clarity.
✅ Subject: Programming In Java
📅 Week: 2
🎯 Session: NPTEL 2025 July-October
🔗 Course Link: Click Here
🔍 Reliability: Verified and expert-reviewed answers
📌 Trusted By: 5000+ Students
For complete and in-depth solutions to all weekly assignments, check out 👉 NPTEL Programming In Java Week 2 NPTEL Assignment Answers
🚀 Stay ahead in your NPTEL journey with fresh, updated solutions every week!
NPTEL Programming In Java Week 2 Assignment Answers 2024
1. Which of the following is the correct way to declare a class in Java?
a. public class MyClass f)
b. class MyClass[] 0)
c. public MyClass class t)
d. MyClass public class t)
Answer :
2.

Answer :
3.

Answer :
4. Which keyword is used in Java to refer to the current object?
a. that
b. self
c. current
d. this
Answer :
5. Which of the following is true about constructors in a class?
a. Constructors do not have a return type.
b. Constructors aren’t used to initialize objects.
c. A class can have only one constructor.
d. Constructors cannot be overloaded.
Answer :
6.

Answer :
7.

Answer :
8. Which class is used in Java to take runtime data input from the user?
a. BufferReader
b. UserInputStreamReader
c. Scanner
d. DatalnputStreamReader
Answer :
9. How do you read a line of text from the console using the Scanner class in Java?
a. scanner.readLine()
b. scanner.nextLine()
c. scanner.getLine()
d. scanner.fetchLine()
Answer :
10. What is the correct signature of the main method in Java?
a. public void main(String args [])
b. public static void main(String[] args)
c. void main(String] args)
d. public static void main(String args [])
Answer :
NPTEL Programming In Java Week 2 Assignment Answers 2024
1. In Java programming an object can take many forms. This feature is called ______.
a. Abstraction
b. Polymorphism
c. Encapsulation
d. Inheritance
Answer: b
Explanation:
Polymorphism means “many forms.” In Java, it allows objects to be treated as instances of their parent class, enabling method overriding and overloading.
2. 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
Explanation:
Correct syntax to create an object is: ClassName obj = new ClassName();. Only option (a) follows this format.
3. 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
Explanation:
A default constructor is one that takes no parameters and is either defined by the programmer or created automatically if no constructors are defined.
4. A top-level class may have which one of the following access modifiers?
a. package
b. private
c. protected
d. public
Answer: d
Explanation:
Top-level classes in Java can only be declared as public or with default (package-private) access. Options private and protected are not allowed.
5. Integer in Java is a/an _______.
a. Adapter class
b. Inner class
c. Not a class
d. Wrapper class
Answer: d
Explanation:Integer is a wrapper class in Java. It wraps a primitive int in an object, allowing it to be used where objects are required (like collections).
6. 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
Explanation:
The new operator in Java allocates memory for a new object and returns a reference to it.
7. Which one is not supported by OOP?
a. Abstraction
b. Polymorphism
c. Encapsulation
d. Global variables
Answer: d
Explanation:
Global variables are generally avoided in Object-Oriented Programming as they violate encapsulation and can lead to tight coupling.
8. 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
Explanation:
The final keyword in Java prevents a method from being overridden in subclasses.
9.
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
Explanation:
Since code is not shown, but based on Java syntax-related MCQs, usually line 2 has an error like wrong constructor definition or variable declaration — typical in such questions.
10. 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
Explanation:println() prints the given content and moves the cursor to the next line (adds a newline). print() does not move to the next line automatically.


