SlideShare uma empresa Scribd logo
1 de 29
CHAPTER - 06
CONSTRUCTORS AND DESTRUCTORS
Unit I
Programming and Computational
Thinking (PCT-2)
(80 Theory + 70 Practical)
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)
Department of Computer Science, Sainik School Amaravathinagar
Cell No: 9431453730
Praveen M Jigajinni
Prepared by
Courtesy CBSE
Class XII
INTRODUCTION - CONSTRUCTOR
CONSTRUCTOR
Constructor is a special type of function that
is called automatically whenever an object of
that class is created.
General format or syntax :
def __init__(self):
# body of the constructor
Once the object is created, you can
make sure that every variable in the object is
correctly initialised by defining
an __init__ method in your class, which
pretty much means init-iate.
CONSTRUCTOR EXAMPLE (CODE)
CONSTRUCTOR EXAMPLE (O/P)
TYPES OF CONSTRUCTOR
TYPES OF CONSTRUCTOR
We have two types of constructors in
Python.
1. default constructor – this is the one, which we
have seen in the above example. This
constructor doesn’t accept any arguments.
2. parameterized constructor – constructor with
parameters is known as parameterized
constructor.
DEFAULT CONSTRUCTOR EXAMPLE
PARAMETERIZED CONSTRUCTOR EXAMPLE (CODE)
PARAMETERIZED CONSTRUCTOR EXAMPLE (O/P)
DESTRUCTOR
DESTRUCTOR
Destructors are called when an object
gets destroyed. It’s the polar opposite of the
constructor, which gets called on creation.
Destructor can be very useful for releasing
resources before coming out of the program like
closing files, releasing memories etc
Destructor is defined using __del__() keyword
DESTRUCTOR CODE
__del__(self) destructor Method
DESTRUCTOR
Destructor method called automatically and object
is destroyed
PYTHON GARBAGE COLLECTION
Python deletes unneeded objects (built-in
types or class instances) automatically to free the
memory space.
The process by which Python periodically
reclaims blocks of memory that no longer are in
use is termed as Garbage Collection.
Python's garbage collector runs during
program execution and is triggered when an
object's reference count reaches zero.
END OF CHAPTER
SOLVIING CBSE QUESTION PAPER 2(C) 4 Marks
PROGRAMS ON CLASSES
CBSE QUESTION PAPER - 2015 DELHI
(c) Write a class PICTURE in Python with following
specifications : 4
Instance Attributes
– Pno # Numeric value
– Category # String value
– Location # Exhibition Location with
# String value
Methods :
– FixLocation() # A method to assign
# Exhibition Location as per
#Category
# as shown in the following table
CBSE QUESTION PAPER - 2015 DELHI
– Enter() # A function to allow user to
enter values
# Pno, Category and call
FixLocation() method
– SeeAll() # A function to display all the
data members
Category Location
Classic Amina
Modern Jim Plaq
Antique Ustad Khan
CBSE QUESTION PAPER - 2015 DELHI
CBSE QUESTION PAPER - 2015 OUTSIDE DELHI
(c) Write a class PHOTO in Python with following
specifications : 4
Instance Attributes
– Pno # Numeric value
– Category # String Value
– Exhibit # Exhibition Gallery with String value
Methods:
– FixExhibit() #A method to assign
#Exhibition Gallery as per
#Category
#as shown in the following table
CBSE QUESTION PAPER - 2015 DELHI
CBSE QUESTION PAPER - 2015 DELHI
Category Exhibit
Antique Zaveri
Modern Johnsen
Classic Terenida
-Register() #A function to allow user to
enter values #Pno, Category
and call FixExhibit() method
– ViewAll() #A function to display all the
data members
CBSE QUESTION PAPER - 2016 DELHI
CBSE QUESTION PAPER - 2016 DELHI
(c) Write a class CITY in Python with following
specifications : 4
Instance Attributes
– Code # Numeric value
– Name # String value
– Pop # Numeric value for Population
– KM # Numeric value
– Density # Numeric value for Population
Density than 12000.
CBSE QUESTION PAPER - 2016 DELHI
Methods:
– CalDen() # Method to calculate Density
as Pop/KM
– Record() # Method to allow user to
enter values Code, Name, Pop,
KM and call CalDen() method
– See() # Method to display all the
data members also display a
message “Highly Populated
Area” if the Density is more
than 12000.
CLASS TEST
1. What is Constructor? Explain
2. What are the types of constructors?
3. What is destructors? Explain
4. Write a program to illustrate constructors
5. Write a program to illustrate distructors
Class : XII Time: 40 Min
Topic: Const & distruct Max Marks: 20
Each Question carries 4 marks
Thank You

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 

Semelhante a Chapter 06 constructors and destructors

SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSnikshaikh786
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ Dev Chauhan
 
Python-oop
Python-oopPython-oop
Python-oopRTS Tech
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Yung-Yu Chen
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete  Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete Adnan abid
 
Introduction to Python.Net
Introduction to Python.NetIntroduction to Python.Net
Introduction to Python.NetStefan Schukat
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at JetC4Media
 

Semelhante a Chapter 06 constructors and destructors (20)

SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUS
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
17515
1751517515
17515
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
Python-oop
Python-oopPython-oop
Python-oop
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
C++chapter2671
C++chapter2671C++chapter2671
C++chapter2671
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete  Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete
 
Introduction to Python.Net
Introduction to Python.NetIntroduction to Python.Net
Introduction to Python.Net
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
 

Mais de Praveen M Jigajinni

Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithmsPraveen M Jigajinni
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programmingPraveen M Jigajinni
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with pythonPraveen M Jigajinni
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingPraveen M Jigajinni
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow chartsPraveen M Jigajinni
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingPraveen M Jigajinni
 

Mais de Praveen M Jigajinni (20)

Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithms
 
Chapter 08 data file handling
Chapter 08 data file handlingChapter 08 data file handling
Chapter 08 data file handling
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
Chapter 17 Tuples
Chapter 17 TuplesChapter 17 Tuples
Chapter 17 Tuples
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Chapter 13 exceptional handling
Chapter 13 exceptional handlingChapter 13 exceptional handling
Chapter 13 exceptional handling
 
Chapter 10 data handling
Chapter 10 data handlingChapter 10 data handling
Chapter 10 data handling
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with python
 
Chapter 7 basics of computational thinking
Chapter 7 basics of computational thinkingChapter 7 basics of computational thinking
Chapter 7 basics of computational thinking
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow charts
 
Chapter 5 boolean algebra
Chapter 5 boolean algebraChapter 5 boolean algebra
Chapter 5 boolean algebra
 
Chapter 4 number system
Chapter 4 number systemChapter 4 number system
Chapter 4 number system
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computing
 
Chapter 2 operating systems
Chapter 2 operating systemsChapter 2 operating systems
Chapter 2 operating systems
 
Chapter 1 computer fundamentals
Chapter 1 computer  fundamentalsChapter 1 computer  fundamentals
Chapter 1 computer fundamentals
 

Último

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Último (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Chapter 06 constructors and destructors

  • 1. CHAPTER - 06 CONSTRUCTORS AND DESTRUCTORS
  • 2. Unit I Programming and Computational Thinking (PCT-2) (80 Theory + 70 Practical) DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci) Department of Computer Science, Sainik School Amaravathinagar Cell No: 9431453730 Praveen M Jigajinni Prepared by Courtesy CBSE Class XII
  • 4. CONSTRUCTOR Constructor is a special type of function that is called automatically whenever an object of that class is created. General format or syntax : def __init__(self): # body of the constructor Once the object is created, you can make sure that every variable in the object is correctly initialised by defining an __init__ method in your class, which pretty much means init-iate.
  • 8. TYPES OF CONSTRUCTOR We have two types of constructors in Python. 1. default constructor – this is the one, which we have seen in the above example. This constructor doesn’t accept any arguments. 2. parameterized constructor – constructor with parameters is known as parameterized constructor.
  • 13. DESTRUCTOR Destructors are called when an object gets destroyed. It’s the polar opposite of the constructor, which gets called on creation. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc Destructor is defined using __del__() keyword
  • 15. DESTRUCTOR Destructor method called automatically and object is destroyed
  • 16. PYTHON GARBAGE COLLECTION Python deletes unneeded objects (built-in types or class instances) automatically to free the memory space. The process by which Python periodically reclaims blocks of memory that no longer are in use is termed as Garbage Collection. Python's garbage collector runs during program execution and is triggered when an object's reference count reaches zero.
  • 18. SOLVIING CBSE QUESTION PAPER 2(C) 4 Marks PROGRAMS ON CLASSES
  • 19. CBSE QUESTION PAPER - 2015 DELHI
  • 20. (c) Write a class PICTURE in Python with following specifications : 4 Instance Attributes – Pno # Numeric value – Category # String value – Location # Exhibition Location with # String value Methods : – FixLocation() # A method to assign # Exhibition Location as per #Category # as shown in the following table CBSE QUESTION PAPER - 2015 DELHI
  • 21. – Enter() # A function to allow user to enter values # Pno, Category and call FixLocation() method – SeeAll() # A function to display all the data members Category Location Classic Amina Modern Jim Plaq Antique Ustad Khan CBSE QUESTION PAPER - 2015 DELHI
  • 22. CBSE QUESTION PAPER - 2015 OUTSIDE DELHI
  • 23. (c) Write a class PHOTO in Python with following specifications : 4 Instance Attributes – Pno # Numeric value – Category # String Value – Exhibit # Exhibition Gallery with String value Methods: – FixExhibit() #A method to assign #Exhibition Gallery as per #Category #as shown in the following table CBSE QUESTION PAPER - 2015 DELHI
  • 24. CBSE QUESTION PAPER - 2015 DELHI Category Exhibit Antique Zaveri Modern Johnsen Classic Terenida -Register() #A function to allow user to enter values #Pno, Category and call FixExhibit() method – ViewAll() #A function to display all the data members
  • 25. CBSE QUESTION PAPER - 2016 DELHI
  • 26. CBSE QUESTION PAPER - 2016 DELHI (c) Write a class CITY in Python with following specifications : 4 Instance Attributes – Code # Numeric value – Name # String value – Pop # Numeric value for Population – KM # Numeric value – Density # Numeric value for Population Density than 12000.
  • 27. CBSE QUESTION PAPER - 2016 DELHI Methods: – CalDen() # Method to calculate Density as Pop/KM – Record() # Method to allow user to enter values Code, Name, Pop, KM and call CalDen() method – See() # Method to display all the data members also display a message “Highly Populated Area” if the Density is more than 12000.
  • 28. CLASS TEST 1. What is Constructor? Explain 2. What are the types of constructors? 3. What is destructors? Explain 4. Write a program to illustrate constructors 5. Write a program to illustrate distructors Class : XII Time: 40 Min Topic: Const & distruct Max Marks: 20 Each Question carries 4 marks