0% found this document useful (0 votes)
6 views29 pages

Unit 7 Classes and Objects

Uploaded by

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

Unit 7 Classes and Objects

Uploaded by

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

 Describe classes and objects in C#.

 Create classes and objects.


 Explain constructors and destructors in C#.
 Add constructor and destructor in a class.
MODIFIER ACCESSIBILITY CONTROL

Private Member is accessible only within the class containing the


member.

Public Member is accessible from anywhere outside the class as well.


It is also accessible in derived classes.

protected Member is visible only to its own class and its derived classes.
class mul
{
public int n, m; //declaring class variables
public void add() //define add() method
{
int s;
s = n + m;
Console.WriteLine("Sum="+s);
}
public void sub() //define sub() method
{
int d;
d = n - m;
Console.WriteLine("Difference=" + d);
}
}
class Program
{
static void Main(string[] args)
{
mul obj1 = new mul(); //obj1 is the object of mul class
obj1.n = Convert.ToInt32(Console.ReadLine());
obj1.m = Convert.ToInt32(Console.ReadLine());
obj1.add(); //calling add() method
obj1.sub(); //calling sub() method
Console.ReadLine();
}
}
Output
 This chapter explains:-

›Creation of classes and objects.


›Adding variables and methods in a class.
›Accessing class members
›Creation of constructors and destructors in a class.

You might also like