SlideShare uma empresa Scribd logo
1 de 19
A Programme Under the compumitra Series
Programming Primer - INHERITANCE
LAB WORK GUIDE
1
OUTLINE
Inheritance Using C# in asp.net
A Parent-Child Class Example.
Example Explanation.
Home Exercise.
Summary
2
Inheritance
Using C# in asp.net
3
InheritanceCS -Web Site Creation-1
From Start Page Click New Website and reach this screen
2. Select 'ASP.NET Empty Web Site'
3. Select Location=File System
4. Click 'Browse..' tab to
select the location where
you want to save your Web
Site
5. click 'OK'
1. Select Language=Visual C#
 By default Your Web Site shall be saved in the Location- "C:Documents and
SettingsMy DocumentsVisual Studio 2008WebSites." Change it to
 "C:Learner<student-id>ProgrammingPrimerInheritanceCS" folder4
InheritanceCS -Web Site Creation-2
In the Solution Explorer Window
Select the path -> Right click ->
Add New Item…
5
InheritanceCS -Web Site Creation-3 'Add New Item' dialog box will open
1. Select 'Web Form'
2. Simply Click on
'Add' button
6
InheritanceCS – Creating a Button to create an event handler
2. Set the 'Text' Property
equal to 'Inheritance'
1. Select and Drag and Drop
'Button' in div
7
InheritanceCS – Creating Output Display Placeholders Using Label
4. Set the 'Text' Property
equal to 'Blank'
1. Press 'Enter' key to bring the
cursor one line below.
2. Select and Drag and Drop
Two 'Labels' in div
Like 'Label1', Set the 'Text Property' of 'Label2'.
3. Select the 'label1'
8
InheritanceCS – Copy Code-1
Child c = new Child();
string n;
n = c.C1();
Label1.Text = n;
string m;
m = c.P1();
Label2.Text = m;
Copy this Code
9
InheritanceCS -Paste Code-1
Go to 'Default.aspx.cs' by double clicking on
'Button' ('Inheritance' Button)
of 'Default.aspx' and
'Paste' the Code in 'Button1_Click' handler.
Child c = new Child();
string n;
n = c.C1();
Label1.Text = n;
string m;
m = c.P1();
Label2.Text = m;
10
InheritanceCS – Copy Code -2
public class Parent
{
string s;
public string P1()
{
s = "Parent P1";
return s;
}
}
public class Child : Parent
{
string r;
public string C1()
{
r = "Child C1";
return r;
}
}
Copy this Code
11
InheritanceCS - Paste Code-2
Run Code By
pressing 'F5'
'Paste' code after the End
of '_Default' class
public class Parent
{
string s;
public string P1()
{
s = "Parent P1";
return s;
}
}
public class Child : Parent
{
string r;
public string C1()
{
r = "Child C1";
return r;
}
}
Child c = new Child();
string n;
n = c.C1();
Label1.Text = n;
string m;
m = c.P1();
Label2.Text = m;
12
InheritanceCS -Output
Click on
'Inheritance'
button.
Output on browser
Output after clicking 'Inheritance' button.
Output from 'P1 Function' of
'Parent' class, although called
using a child class object.
Output from 'C1
Function' of 'Child' class
13
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Child c = new Child();
string n;
n = c.C1();
Label1.Text = n;
string m;
m = c.P1();
Label2.Text = m;
}
}
public class Parent
{ string m;
public string P1()
{ m = "Parent P1" ;
return m;
}
}
public class Child : Parent
{ string r;
public string C1()
{ r = "Child C1";
return r;
}
}
InheritanceCS - Example Explanation -1
This is 'Child' class, which 'Inherits'
'Parent' class and has 'C1' function
This is 'Parent' class, which has
'P1' function.
This statement creates the
object 'c' of 'Child' class.
This statement uses the object 'c' of 'Child'
class but using a method in 'parent' class.
This is possible due to INHERITANCE.
This statement uses the object 'c' of 'Child'
class using a method in 'Child' class itself.
This is normal usage.
14
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Child c = new Child();
string n;
n = c.C1();
Label1.Text = n;
string m;
m = c.P1();
Label2.Text = m;
}
}
public class Parent
{ string m;
public string P1()
{ m = "Parent P1" ;
return m;
}
}
public class Child : Parent
{ string r;
public string C1()
{ r = "Child C1";
return r;
}
}
InheritanceCS- Example Explanation - 2
This is 'C1' function of 'Child' class.
This statement 'returns' the value
of 'r'.
This statement calls the function 'C1' of
'Child' class and stores returned value in 'n'
which is output in next line as "Child C1"
This statement calls the function 'P1' of 'Child'
class and stores returned value in 'm' which is
output in next line as "Parent P1"
This is 'P1' function of 'Parent' class.
15
InheritanceCS- Example Explanation - 3
'n=c.C1( )' statement calls the function 'C1' of
'Child' class.
'm=c.P1( )' statement calls the function 'P1' of
'Parent' class. This is actually done using a child
class object.
16
InheritanceCS: Home Exercise
 Write a program similar to the example given which can demonstrate
two classes "polygon" and a child class "square". From the main routine,
Use class "polygon" to return the string "sides" and use class "square" to
return the string "4".
Finally display the string, "I am a polygon called square, I have 4 sides".
Remember that the program should be based on INHERITANCE.
 You can further extend this program where a user inputs the name of a
polygon and based on user's provided name the program returns number
of sides. For example input triangle to return "3 sides" and square to
return "4 sides".
 Modify any of these programs to test whether a parent class object can use
methods or properties from child class.
17
InheritanceCS : Learning Summary Review
Concept of Inheritance
Child class inherits properties of parent class.
Objects created from child class can always use
methods and properties from parent class. (The
reverse is not true).
Programming techniques to create classes,
and subclasses.
Programming techniques to return values.
Programming techniques to concatenate
strings.
18
Ask and guide me at
sunmitraeducation@gmail.com
Share this information with as
many people as possible.
Keep visiting www.sunmitra.com
for programme updates.
19

Mais conteúdo relacionado

Semelhante a Programming Primer Inheritance CS

Database By Salman Mushtaq
Database By Salman MushtaqDatabase By Salman Mushtaq
Database By Salman MushtaqSalman Mushtaq
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseRalf Sternberg
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedgovendaagoovenda
 
Ooabapnoteswithprogram good 78
Ooabapnoteswithprogram good 78Ooabapnoteswithprogram good 78
Ooabapnoteswithprogram good 78Yogesh Mehra
 
Ooabap notes with_programs
Ooabap notes with_programsOoabap notes with_programs
Ooabap notes with_programsKranthi Kumar
 
6.1.2 用eclipse环境调试一步一步学repast操作
6.1.2 用eclipse环境调试一步一步学repast操作6.1.2 用eclipse环境调试一步一步学repast操作
6.1.2 用eclipse环境调试一步一步学repast操作zhang shuren
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfadityastores21
 
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
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfROWELL MARQUINA
 
CIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.comCIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.combellflower82
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   llflowe
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   bellflower42
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfssuser33f16f
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com amaranthbeg143
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 

Semelhante a Programming Primer Inheritance CS (20)

Database By Salman Mushtaq
Database By Salman MushtaqDatabase By Salman Mushtaq
Database By Salman Mushtaq
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
 
Ooabapnoteswithprogram good 78
Ooabapnoteswithprogram good 78Ooabapnoteswithprogram good 78
Ooabapnoteswithprogram good 78
 
Ooabap notes with_programs
Ooabap notes with_programsOoabap notes with_programs
Ooabap notes with_programs
 
6.1.2 用eclipse环境调试一步一步学repast操作
6.1.2 用eclipse环境调试一步一步学repast操作6.1.2 用eclipse环境调试一步一步学repast操作
6.1.2 用eclipse环境调试一步一步学repast操作
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdf
 
Unit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docxUnit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docx
 
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
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdf
 
A d swincc15e
A d swincc15eA d swincc15e
A d swincc15e
 
Hems
HemsHems
Hems
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
CIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.comCIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.com
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Ch02.pdf
Ch02.pdfCh02.pdf
Ch02.pdf
 

Mais de sunmitraeducation

Mais de sunmitraeducation (20)

Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Installing JDK and first java program
Installing JDK and first java programInstalling JDK and first java program
Installing JDK and first java program
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
 
Project1 CS
Project1 CSProject1 CS
Project1 CS
 
Grid Vew Control VB
Grid Vew Control VBGrid Vew Control VB
Grid Vew Control VB
 
Grid View Control CS
Grid View Control CSGrid View Control CS
Grid View Control CS
 
Ms Access
Ms AccessMs Access
Ms Access
 
Database Basics Theory
Database Basics TheoryDatabase Basics Theory
Database Basics Theory
 
Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3
 
Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3
 
Progamming Primer Polymorphism (Method Overloading) VB
Progamming Primer Polymorphism (Method Overloading) VBProgamming Primer Polymorphism (Method Overloading) VB
Progamming Primer Polymorphism (Method Overloading) VB
 
Programming Primer EncapsulationVB
Programming Primer EncapsulationVBProgramming Primer EncapsulationVB
Programming Primer EncapsulationVB
 
Programming Primer Encapsulation CS
Programming Primer Encapsulation CSProgramming Primer Encapsulation CS
Programming Primer Encapsulation CS
 
ProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPSProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPS
 
Web Server Controls VB Set 1
Web Server Controls VB Set 1Web Server Controls VB Set 1
Web Server Controls VB Set 1
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
 
Web Controls Set-1
Web Controls Set-1Web Controls Set-1
Web Controls Set-1
 
Understanding IDEs
Understanding IDEsUnderstanding IDEs
Understanding IDEs
 
Html Server Image Control VB
Html Server Image Control VBHtml Server Image Control VB
Html Server Image Control VB
 
Html Server Image Control CS
Html Server Image Control CSHtml Server Image Control CS
Html Server Image Control CS
 

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Programming Primer Inheritance CS

  • 1. A Programme Under the compumitra Series Programming Primer - INHERITANCE LAB WORK GUIDE 1
  • 2. OUTLINE Inheritance Using C# in asp.net A Parent-Child Class Example. Example Explanation. Home Exercise. Summary 2
  • 4. InheritanceCS -Web Site Creation-1 From Start Page Click New Website and reach this screen 2. Select 'ASP.NET Empty Web Site' 3. Select Location=File System 4. Click 'Browse..' tab to select the location where you want to save your Web Site 5. click 'OK' 1. Select Language=Visual C#  By default Your Web Site shall be saved in the Location- "C:Documents and SettingsMy DocumentsVisual Studio 2008WebSites." Change it to  "C:Learner<student-id>ProgrammingPrimerInheritanceCS" folder4
  • 5. InheritanceCS -Web Site Creation-2 In the Solution Explorer Window Select the path -> Right click -> Add New Item… 5
  • 6. InheritanceCS -Web Site Creation-3 'Add New Item' dialog box will open 1. Select 'Web Form' 2. Simply Click on 'Add' button 6
  • 7. InheritanceCS – Creating a Button to create an event handler 2. Set the 'Text' Property equal to 'Inheritance' 1. Select and Drag and Drop 'Button' in div 7
  • 8. InheritanceCS – Creating Output Display Placeholders Using Label 4. Set the 'Text' Property equal to 'Blank' 1. Press 'Enter' key to bring the cursor one line below. 2. Select and Drag and Drop Two 'Labels' in div Like 'Label1', Set the 'Text Property' of 'Label2'. 3. Select the 'label1' 8
  • 9. InheritanceCS – Copy Code-1 Child c = new Child(); string n; n = c.C1(); Label1.Text = n; string m; m = c.P1(); Label2.Text = m; Copy this Code 9
  • 10. InheritanceCS -Paste Code-1 Go to 'Default.aspx.cs' by double clicking on 'Button' ('Inheritance' Button) of 'Default.aspx' and 'Paste' the Code in 'Button1_Click' handler. Child c = new Child(); string n; n = c.C1(); Label1.Text = n; string m; m = c.P1(); Label2.Text = m; 10
  • 11. InheritanceCS – Copy Code -2 public class Parent { string s; public string P1() { s = "Parent P1"; return s; } } public class Child : Parent { string r; public string C1() { r = "Child C1"; return r; } } Copy this Code 11
  • 12. InheritanceCS - Paste Code-2 Run Code By pressing 'F5' 'Paste' code after the End of '_Default' class public class Parent { string s; public string P1() { s = "Parent P1"; return s; } } public class Child : Parent { string r; public string C1() { r = "Child C1"; return r; } } Child c = new Child(); string n; n = c.C1(); Label1.Text = n; string m; m = c.P1(); Label2.Text = m; 12
  • 13. InheritanceCS -Output Click on 'Inheritance' button. Output on browser Output after clicking 'Inheritance' button. Output from 'P1 Function' of 'Parent' class, although called using a child class object. Output from 'C1 Function' of 'Child' class 13
  • 14. public partial class _Default : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { Child c = new Child(); string n; n = c.C1(); Label1.Text = n; string m; m = c.P1(); Label2.Text = m; } } public class Parent { string m; public string P1() { m = "Parent P1" ; return m; } } public class Child : Parent { string r; public string C1() { r = "Child C1"; return r; } } InheritanceCS - Example Explanation -1 This is 'Child' class, which 'Inherits' 'Parent' class and has 'C1' function This is 'Parent' class, which has 'P1' function. This statement creates the object 'c' of 'Child' class. This statement uses the object 'c' of 'Child' class but using a method in 'parent' class. This is possible due to INHERITANCE. This statement uses the object 'c' of 'Child' class using a method in 'Child' class itself. This is normal usage. 14
  • 15. public partial class _Default : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { Child c = new Child(); string n; n = c.C1(); Label1.Text = n; string m; m = c.P1(); Label2.Text = m; } } public class Parent { string m; public string P1() { m = "Parent P1" ; return m; } } public class Child : Parent { string r; public string C1() { r = "Child C1"; return r; } } InheritanceCS- Example Explanation - 2 This is 'C1' function of 'Child' class. This statement 'returns' the value of 'r'. This statement calls the function 'C1' of 'Child' class and stores returned value in 'n' which is output in next line as "Child C1" This statement calls the function 'P1' of 'Child' class and stores returned value in 'm' which is output in next line as "Parent P1" This is 'P1' function of 'Parent' class. 15
  • 16. InheritanceCS- Example Explanation - 3 'n=c.C1( )' statement calls the function 'C1' of 'Child' class. 'm=c.P1( )' statement calls the function 'P1' of 'Parent' class. This is actually done using a child class object. 16
  • 17. InheritanceCS: Home Exercise  Write a program similar to the example given which can demonstrate two classes "polygon" and a child class "square". From the main routine, Use class "polygon" to return the string "sides" and use class "square" to return the string "4". Finally display the string, "I am a polygon called square, I have 4 sides". Remember that the program should be based on INHERITANCE.  You can further extend this program where a user inputs the name of a polygon and based on user's provided name the program returns number of sides. For example input triangle to return "3 sides" and square to return "4 sides".  Modify any of these programs to test whether a parent class object can use methods or properties from child class. 17
  • 18. InheritanceCS : Learning Summary Review Concept of Inheritance Child class inherits properties of parent class. Objects created from child class can always use methods and properties from parent class. (The reverse is not true). Programming techniques to create classes, and subclasses. Programming techniques to return values. Programming techniques to concatenate strings. 18
  • 19. Ask and guide me at sunmitraeducation@gmail.com Share this information with as many people as possible. Keep visiting www.sunmitra.com for programme updates. 19