Nptel Programming in Java Week 2 Assignment Answers

Searching for the Week 2 answers of the NPTEL “Programming in Java” course? You’re in the right spot! Here, you’ll find reliable and up-to-date solutions to help you complete your Week 2 assignment with confidence.

Nptel Programming in Java Week 2 Assignment Answers

Programming In Java

ABOUT THE COURSE :
With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.
INTENDED AUDIENCE :  The undergraduate students from the engineering disciplines namely CSE, IT, EE, ECE, etc. might be interested for this course.

PREREQUISITES :  
This course requires that the students are familiar with programming language such as C/C++ and data structures, algorithms.

INDUSTRY SUPPORT : 
  All IT companies.

COURSE LAYOUT – Click To Know More

Week 1  :  Overview of Object-Oriented Programming and Java
Week 2  :  Java Programming Elements
Week 3  :  Input-Output Handling in Java
Week 4  :  Encapsulation
Week 5  :  Inheritance
Week 6  :  Exception Handling
Week 7  :  Multithreaded Programming
Week 8  :  Java Applets and Servlets
Week 9  :  Java Swing and Abstract Windowing Toolkit (AWT)
Week 10 : Networking with Java
Week 11 :  Java Object Database Connectivity (ODBC)
Week 12 :  Interface and Packages for Software Development
Unlocking the fundamentals of Java programming, the NPTEL Week 2 assignment is designed to introduce learners to the core concepts of this powerful object-oriented language. From understanding Java’s syntax and structure to writing simple programs, this week lays the foundation for a deeper journey into Java development. In this post, we provide clear and concise solutions to the Week 2 assignment, ensuring clarity for beginners while adhering to academic integrity and learning goals. Dive in to reinforce your concepts and validate your approach.
Get All Week Nptel Assignment Answers – Click Here

Nptel Programming in Java Week 2 Assignment Answers

  1. Consider the following object declaration statement:
    Scanner = new Scanner(System.in);
    What does System.in stand for in the above declaration?
    a. Any file storing data
    b. Refers to the standard input stream, which is typically the keyboard by default
    c. Reference to scanner as an input device
    d. It is a mouse as an input device

View Answer


  1. What will be the output of the following Java program?
public class VarPrint {
    int x;
    static int y = 20;
    public static void main(String[] args) {
        VarPrint t1 = new VarPrint();
        t1.x = 88;
        int z1 = t1.x + t1.y;
        VarPrint t2 = new VarPrint();
        System.out.println(t2.x + " " + z1);
    }
}

a. 30 99 178
b. 30 88 129
c. 30 99 187
d. 88 99 178

View Answer


  1. What will be the output of the following Java program?
public class ArgumenTest {
    public static void main(String[] args) {
        Test t = new Test();
        t.start();
    }

    static class Test {
        int a, b;
        void start() {
            System.out.print(a + b);
            System.out.print(" ");
            System.out.print(foo() + a);
            System.out.println(a + b + foo());
        }
        String foo() {
            return " foo";
        }
    }
}

a. 97 7 foo 34 34foo
b. 83 9 45 foo 45 9foo
c. 72 34 34 foo 34 34foo
d. 97 foo 7 7foo

View Answer


  1. What is encapsulation in object-oriented programming?
    a. Hiding implementation details and exposing only functionality
    b. The process of creating multiple objects in a program
    c. Writing multiple methods in a single class
    d. Using the this keyword to reference an object

View Answer

For Latest Update Join our official channel: Click here to join


  1. Which of the following is true about constructors in a class?
    a. Constructors must have a return type
    b. Constructors are used to initialize objects
    c. A class can have only one constructor
    d. Constructors cannot be overloaded

View Answer


  1. What does the this keyword in Java help to achieve?
    a. Avoiding namespace collision between instance variables and method parameters
    b. Overloading methods in a class
    c. Accessing private methods in another class
    d. Creating multiple objects in a program

View Answer


  1. 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()

View Answer


  1. Which of the following is used to take runtime input in Java?
    a. BufferedReader
    b. Scanner
    c. DataInputStream
    d. All of the above

View Answer

For Latest Update Join our official channel: Click here to join


  1. Which method is used to format output in Java?
    a. print()
    b. println()
    c. printf()
    d. format()

View Answer


  1. Which Java class is primarily used to read input from the console?
    a. Scanner
    b. BufferedReader
    c. Console
    d. DataInputStream

View Answer

Nptel Programming in Java Week 3 Assignment Answers – Click Here