0% found this document useful (0 votes)
24 views6 pages

Week-01 July22

Uploaded by

Debasish Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Week-01 July22

Uploaded by

Debasish Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

DATA STRUCTURES AND ALGORITHMS USING JAVA


Assignment 1
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10× 1 = 10
______________________________________________________________________________

QUESTION 1:

Which feature can be implemented using encapsulation?

a. Inheritance
b. Abstraction
c. Polymorphism
d. Overloading

Correct Answer: b

Detailed Solution:
Abstraction in Java implies defining a class encapsulation both data and method.
____________________________________________________________________________

QUESTION 2:

Which of the following best describes encapsulation?

a. It is a way of combining various data members into a single unit.


b. It is a way of combining various member functions into a single unit.
c. It is a way of combining various data members and member functions into a single unit which can
operate on any data.
d. It is a way of combining various data members and member functions that operate on those data
members into a single unit.

Correct Answer: d

Detailed Solution:
It is a way of combining both data members and member functions, which operate on those data
members, into a single unit. We call it a class in OOP generally. This feature has helped us
modify the structures used in C language to be upgraded into classes in C++ and JAVA
language.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

___________________________________________________________________________

QUESTION 3:

Which of the following should be encapsulated?

a. The data which is prone to change is near future.


b. The data prone to change in long terms.
c. The data which is intended to be changed.
d. The data which belongs to some other class.

Correct Answer: a

Detailed Solution:
The data prone to change in near future is usually encapsulated so that it doesn’t get changed
accidentally. We encapsulate the data to hide the critical working of program from outside world.

___________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

import java.io.*;
class Q
{
public static void swap(int x, int y)
{
int temp;
temp = x;
y = x;
y = temp;
System.out.print(x + " " + y);

}
public static void main(String[] args)
{
int x = 100;
int y = 10;
swap(x, y);
}
}

What will be the output?


a. 100 10
b. 10 100
c. 10 10
d. 100 100

Correct Answer: d

Detailed Solution:
As per the program, the answer should be 100 100, since the variables are not really swapped
due to an intentional flawed logic.
_________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Why are generics used?

a. Generics make code more fast.


b. Generics make code more optimized and readable.
c. Generics add stability to your code by making more of your bugs detectable at compile time.
d. Generics add stability to your code by making more of your bugs detectable at a runtime.

Correct Answer: c

Detailed Solution:
Refer to the lectures
________________________________________________________________________

QUESTION 6:

Which of the following is true?

a. Generic programming and function overloading are very similar to each other.
b. With method overloading you can pass any type of data argument but with generic programming
it is limited.
c. For generic programming to work, multiple functions of the same logic need to be created for
different data types.
d. Method overriding is a fancy name for method overloading.

Correct Answer: a

Detailed Solution:
Refer to the Lecture 2 of Week-1
___________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

class DemoClass<T> {
void genericPrint(_____)
{
System.out.println(t);
}
public static void main (String[] args) {
DemoClass obj = new DemoClass();
obj.genericPrint("HI");
obj.genericPrint(1000);
}
}

Fill in the missing blank to implement it as a generic program?


a. int t
b. float t
c. double t
d. T t

Correct Answer: d

Detailed Solution:
Refer to Lecture 2 of week-1
___________________________________________________________________________

QUESTION 8:

How do we implement variable sized arguments in generic programming?


a. Array
b. Variable argument
c. varars
d. getch()

Correct Answer: a

Detailed Solution:
Refer to Lecture 2 of Week-1
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

___________________________________________________________________________

QUESTION 9:

<T extends superclass> is used to implement which of the following?

a. Lower bound
b. Upper bound
c. Middle bound
d. None of the above.

Correct Answer: b

Detailed Solution:
Refer to Lecture 5 of Week-1
___________________________________________________________________________

QUESTION 10:

Why do we need to study data structures?

a. Because it's a really hot topic in this era, like Machine Learning, Deep Learning.
b. Because it's an ancient topic and we should know the history of computers
c. It is essential for developing a large, complex and critical software.
d. Data structures help us organize and access different types of data in the most efficient format
according to our needs.

Correct Answer: c, d

Detailed Solution:
The concept od data structures is essential to develop large, complex and critical software. Also,
data structures help to organize and access different types of data in the most efficient ways.

___________________________________________________________________________

************END************

You might also like