0% found this document useful (0 votes)
2 views4 pages

Fundamentals of Object Oriented Programming - - Unit 5 - Week 2 Solved Question

The document outlines the Week 2 assignment for the NPTEL course on Fundamentals of Object Oriented Programming, including questions related to classes, constructors, and destructors in C++. It specifies the due date for submission and provides multiple-choice questions to assess understanding of key concepts in C++. Students are allowed to submit their answers multiple times before the deadline.

Uploaded by

mishraadi9091
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)
2 views4 pages

Fundamentals of Object Oriented Programming - - Unit 5 - Week 2 Solved Question

The document outlines the Week 2 assignment for the NPTEL course on Fundamentals of Object Oriented Programming, including questions related to classes, constructors, and destructors in C++. It specifies the due date for submission and provides multiple-choice questions to assess understanding of key concepts in C++. Students are allowed to submit their answers multiple times before the deadline.

Uploaded by

mishraadi9091
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/ 4

2/5/25, 5:51 PM Fundamentals of Object Oriented Programming - - Unit 5 - Week 2

(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)

[email protected]

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » Fundamentals of Object Oriented Programming

(course)


Click to register
for Certification
exam
Week 2: Assignment 2
(https://examform.nptel.ac.in/2025_01/exam_form/dashboard)
Assignment not submitted Due date: 2025-02-05, 23:59 IST.

If already 1) Which of the following best describes a class in object-oriented programming? 1 point
registered, click
to check your A block of code that defines functions only.
payment status A blueprint for creating objects, encapsulating data and methods.
A template for functions without data.
A data structure for storing primitive data types.

Course
outline 2) What happens when an object is created from a class in C++? 1 point

Memory is allocated for the object’s member variables only.


About NPTEL
Memory is allocated for member functions and variables.
()
Member functions are inherited and memory is allocated for them.
How does an
NPTEL online Member functions are shared across objects, and memory is allocated only for vari-
course work? ables.
()
3) Which of the following statements about constructors is false? 1 point
Week 0 ()
Constructors must have the same name as the class.

Week 1 () Constructors can be overloaded in C++.


Constructors cannot be private in C++.
Week 2 () Constructors do not have a return type.

Classes and
4) In a Java program to define a class Circle with: 1 point
Objects in C++
(unit?
A constructor that initializes its radius.
unit=32&lesson A method getArea() to return the area of the circle.
=33)
Identify the correct syntax to create an object of this class.
Classes and
Objects in Java Circle c1 = new Circle();
and Solved Circle c1 = new Circle(radius);
problems (unit?
Circle c1 = Circle(radius);
unit=32&lesson
=34) Circle c1 = new Circle[radius];

Constructors in
C++: Default
and
Parameterized
(unit?

https://onlinecourses.nptel.ac.in/noc25_cs34/unit?unit=32&assessment=38 1/4
2/5/25, 5:51 PM Fundamentals of Object Oriented Programming - - Unit 5 - Week 2

unit=32&lesson 5) Consider the following C++ code: 1 point


=35)

Constructors in
C++: Copy
Constructor
(unit?
unit=32&lesson
=36)

Constructors in
Java: Default
and
Parameterized
(unit?
unit=32&lesson
=37) What is the output of this program?

Quiz: Week 2:
Assignment 2 Constructor called
(assessment? Display function
name=38) Destructor called

Week 3 () Constructor called


Destructor called
Download Display function
Videos ()
Display function
Weekly Constructor called
Feedback () Destructor called

Constructor called
Display function

6) What is the primary purpose of a destructor in C++? 1 point

To initialize an object when it is created.


To release memory and resources when an object is destroyed.
To overload operators for memory allocation.
To define default behavior for inheritance.

7) Consider the following C++ code: 1 point

What is the output of this program?

Constructor called
Inside createObject function
Destructor called
Before calling createObject
After calling createObject

https://onlinecourses.nptel.ac.in/noc25_cs34/unit?unit=32&assessment=38 2/4
2/5/25, 5:51 PM Fundamentals of Object Oriented Programming - - Unit 5 - Week 2

Before calling createObject


Constructor called
Inside createObject function
Destructor called
After calling createObject

Before calling createObject


Inside createObject function
Constructor called
Destructor called
After calling createObject

Before calling createObject


Constructor called
Inside createObject function
After calling createObject
Destructor called

8) A class in C++ has multiple constructors. How does the compiler decide which 1 point
constructor
to use?

Based on the return type.


Based on the arguments passed during object creation.
The first constructor is always used.
The last constructor is always used.

9) In a C++ program that: 1 point


Defines a class FileHandler with a constructor that opens a file and a destructor that closes
the file.
Demonstrates file handling using objects of this class.

Choose the correct constructor signature:

FileHandler(std::string filename);
FileHandler(char* filename);
FileHandler(const char filename[]);
All of the above

10) Analyze the following C++ code and identify the correct output: 1 point

15
8
Compilation error
Undefined behavior

You may submit any number of times before the due date. The final submission will be considered
for grading.
Submit Answers

https://onlinecourses.nptel.ac.in/noc25_cs34/unit?unit=32&assessment=38 3/4
2/5/25, 5:51 PM Fundamentals of Object Oriented Programming - - Unit 5 - Week 2

https://onlinecourses.nptel.ac.in/noc25_cs34/unit?unit=32&assessment=38 4/4

You might also like