NPTEL Data Structure and Algorithms using Java Week 1 Assignment Answers 2024
1. 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
2. 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
3. Consider the following generic method in Java:
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.
Answer :- Click Here
4. Consider the following Java method:
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 :- Click Here
5. 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 :-
6. 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 :-
7. 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 :- Click Here
8. Which of the following code snippets correctly demonstrates method overloading in Java?
a. A and B
b. B and C
c. D and B
d. All
Answer :-
9. Which of these is a wildcard symbol?
a. ?
b. !
c. &
d. %
Answer :-
10. Which of the following keywords is used to declare an upper bounded wildcard?
a. bound
b. extends
c. implement
d. super
Answer :- Click Here