Data Structure and Algorithms using Java | Week 1

Session: JUL-DEC 2024

Course name: Data Structure and Algorithms using Java

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers


Q1.Which of the following statements is true about linear and non-linear data structures in java?
a. Array and LinkedList are non-linear data structures, while Graph and Tree are linear data structures.
b. Array and LinkedList are linear data structures, while Graph and Tree are non-linear data structures.
c. Array and Graph are linear data structures, while LinkedList and Tree are non-linear data structures.
d. Array and Tree are linear data structures, while LinkedList and Graph are non-linear data structures.

Answer:b. Array and LinkedList are linear data structures, while Graph and Tree are non-linear data structures.


Q2. Which symbol is used to denote a generic type in Java? Which of the following statements is true about this method?
a. *
b. &
c. #
d. <>

Answer: d. <>


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers


Q3. Consider the following generic method in Java:
public static void printArray (T[] array) {
for (T element: array) {
System.out.print(element + “);
}
System.out.println();
}

a. This method can only print arrays of Strings.
b. This method can print arrays of any object type, but not primitive types.
c. This method can print arrays of any type, including primitive types.
d. This method will cause a compile-time error.

See also  Data Structure and Algorithms using Java Week 4 Nptel Answers

Answer: c. This method can print arrays of any type, including primitive types.


Q4. Consider the following Java method:
public static void printVarargs (String… args) {
for (String arg: args) {
System.out.print(arg + “);
}
}Which of the following calls to this method are valid?
A. printVarargs(“Hello”, “World”); B. printVarargs({“Hello”, “World”}); C. printVarargs(new String[]{“Hello”, “World”}); D. printVarargs(new String[]{“Hello”}, “World”);

a. A and B
b. B and C
c. A and C
d. C and D

Answer: a. A and B


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers


Q5. Which of the following statements about variable-length arguments (varargs) is true?
a. A method can have multiple varargs parameters.
b. Varargs parameters must be the first parameter in a method’s parameter list.
c. Varargs parameters can only accept an array of arguments.
d. A method can have only one varargs parameter, and it must be the last parameter in the method’s parameter list.

Answer: d. A method can have only one varargs parameter, and it must be the last parameter in the method’s parameter list.


Q6. Consider the following Java code snippet:
Which of the following statements is true about the given code?

a. The code will produce a compilation error because generic classes cannot be instantiated with primitive types.
b. The code will produce a runtime error when calling getContent on integerBox because of type mismatch.
c. The code will output 123 and Hello.
d. The code will produce a compilation error because the same generic class cannot be used with different types.

Answer: c. The code will output 123 and Hello.

See also  Data Structure and Algorithms using Java Week 2 Nptel Answers

For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers


Q7. Which of the following is true?
a. A generic class may be established with several type parameters.
b. Primitive data types can be utilized as parameter types.
c. It is possible to instantiate an array with an element type that is a type parameter.
d. All of the above

Answer: d. All of the above


Q8.Which of the following code snippets correctly demonstrates method overloading in Java?
A.
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public double add(int a, int b) {
return a b;
B.
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public int add(int a, int b, int c) {
return a + b + c;
C.
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public String add (String a, String b) {
return a + b;

D.
public class Calculator (
public int add(int a, int b) {
return a + b;
}
public int add(int a, int b) {
return a + b + 10;
}

a. A and B
b. B and C
c. D and B
d. All

Answer: d. All


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers


Q9. Which of these is a wildcard symbol?
a. ?
b. !
c. &
d. %

Answer: a. ?


Q10. Which of the following keywords is used to declare an upper bounded wildcard?
a. bound
b. extends
c. implement
d. super

Answer: b. extends


For answers or latest updates join our telegram channel: Click here to join

See also  All About NPTEL

These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers

More Weeks of Data Structure and Algorithms using Java: Click here

More Nptel Courses: https://progiez.com/nptel-assignment-answers


These are Data Structure and Algorithms using Java Week 1 Nptel Assignment Answers