0% found this document useful (0 votes)
87 views12 pages

Visual Programming Language: Classes, Objects, Inheritance, Arrays

The document discusses classes and objects in visual programming languages. It defines what a class is - a template that is used to create objects. Classes contain variables, functions, properties and more. An object is an instance of a class. The document provides examples of how to declare a class, create objects from classes, and use inheritance where a child class inherits from a parent class. It also discusses arrays, showing examples of how to declare, initialize, and access array values.

Uploaded by

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

Visual Programming Language: Classes, Objects, Inheritance, Arrays

The document discusses classes and objects in visual programming languages. It defines what a class is - a template that is used to create objects. Classes contain variables, functions, properties and more. An object is an instance of a class. The document provides examples of how to declare a class, create objects from classes, and use inheritance where a child class inherits from a parent class. It also discusses arrays, showing examples of how to declare, initialize, and access array values.

Uploaded by

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

Visual

Programming
Language
Classes, Objects, Inheritance, Arrays
Classes and Objects

 Class is a template, declaration or blueprint that is used for


classifying object.
 It encapsulates variable members, functions, structure, properties
and many more components. 
 It is the basic building block of object oriented programming. 
 Class is a user defined data type that can contain multiple other
data types in it.
 It can have fields, properties and methods.
 Properties are to get/set values of the fields from outside the class.
 Object is an instance of the class data type (like we says variable of
integer or float etc).
 Class is a reference type therefore we have to allocate its object in
memory by initializing it with ‘new’ operator.

2
In order to create class, the
class keyword is used.
Syntax:
class print
  {
  }
Example:
class print
  {
    public void printname()
     {
       Console.WriteLine(“Iqra University");
     }
  }
3
After creating class, you can
use it by creating its object.
 An object is created using new keyword.
 After creating the object of print class, you can use its
members using the object name as follow:
print pr = new print();
pr.printname();

4
Class - Example Code

class PersonalInfo
{
#region Fields Initializations
string stFirstName;
string stMidName;
string stLastName;
#endregion

#region Properties
public string FirstName
{
get { return stFirstName; }
5
set { stFirstName = value; }
}
PROGRAMMING EXAMPLE
using System;     class Program //Creating 3rd class
using System.Collections.Generic;     {
using System.Linq;         static void Main(string[] args)
using System.Text;         {
              print p = new print();
namespace Creating_Class             p.printdetails();
{             Console.ReadLine();
    class accept //Creating 1st. class         }
    {     }
        public string name; }
        public void acceptdetails()
        {
            Console.Write("Enter your name:\t");
            name = Console.ReadLine();
        }
    }
 
    class print // Creating 2nd class
    {
        public void printdetails()
        {
            //Creating object of 1st. class
            accept a = new accept();
            //executing method of 1st class.
            a.acceptdetails();
            //Printing value of name variable
            Console.WriteLine("Your name is " + a.name); 6
        }
    }
    
GUIDELINE WHILE CREATING
CLASS
 The class name should be noun and meaningful.
 Use either pascal case first letter is capital. Ex.
PascalCase.
 Or camel case, the first letter is small. Ex. camelCase.
 It is strictly recommended you to use pascal case for
class name and camel case for variable name.
 Your class name should not contain any special
character except underscore (_) or digit. Must start your
class name with character.
 Don’t use reserved keyword for class name.

7
INHERITANCE

 One of the important pillar of Object Oriented


Programming (OOP).
 Allows you to access members of base class in child
class.
 It enables you to create a child class that can access
and use all the functionality of its base class.
 This way you can keep common variable and functions
in a base class and use them as many times as you want
in child class.
 Code reusability makes your program simpler and
efficient.

8
EXAMPLE:
using System; //Creating Child Class
using System.Collections.Generic; class Scooter : Tyre
using System.Linq; {
using System.Text; public void ScooterType()
using System.Threading.Tasks; {
Console.WriteLine("Scooter Color is Red");
namespace Basic_Example TyreType();
{ }
class Program }
{ //Creating Child Class
static void Main(string[] args) class Car : Tyre
{ {
Scooter sc = new Scooter(); public void CarType()
sc.ScooterType(); {
Console.WriteLine("Car Type : Ferrari");
Car c = new Car(); TyreType();
c.CarType(); }
}
Console.ReadKey(); }
}
}
//Creating Base Class
class Tyre
{
protected void TyreType()
{
Console.WriteLine("This is Tubeless Tyre");
9
}
}
Arrays
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Declare_Array
{
class Program
{
static void Main(string[] args)
{
int[] num = new int[6]; //Declaring Array

//Initializing array
for (int a = 0; a <= 5; a++)
{
Console.Write(“\nEnter the value of array #" + a + ":\t");
num[a] = int.Parse(Console.ReadLine());
}
/*num[1] = 23;
num[2] = 12;
num[3] = 9;
num[4] = 14;
num[5] = 52;*/
int f = 0;
//Showing value of Array
foreach(int j in num)
{f++;
Console.WriteLine(f+" value:\t{0}", j);
}
/*Console.WriteLine("2nd value:\t{0}", num[1]);
Console.WriteLine("3rd value:\t{0}", num[2]);
Console.WriteLine("4th value:\t{0}", num[3]);
Console.WriteLine("5th value:\t{0}", num[4]);
Console.WriteLine("6th value:\t{0}", num[5]);*/

Console.ReadKey();
} 10
}
}
Storing data in two arrays
using System;  //Accepting name and find their correspondence age in array.
using System.Collections.Generic;  
using System.Linq;             Console.Write("\n\nEnter your name to find age:\t");
using System.Text;             find = Console.ReadLine();
   
namespace accessing_array_value             for (i = 0; i < 6; i++)
{             {
    class Program                 if (name[i] == find)
    {                 {
        static void Main(string[] args)                     Console.WriteLine("\n\nName\t:{0}", name[i]);
        {                     Console.WriteLine("Age\t:{0}", age[i]);
            int[] age = new int[6];                     j++;
            string[] name = new string[6];                 }
            int i, j = 0;             }
            string find;             if (j == 0)
              {
            // Storing users name and age in two different array.                 Console.WriteLine("Not Found!!!");
            for (i = 0; i < 6; i++)             }
            {             Console.ReadLine();
                Console.Write("\n\nEnter your name:\t");         }
                name[i] = Console.ReadLine();     }
                Console.Write("Enter your age:\t\t"); }
                age[i] = Convert.ToInt32(Console.ReadLine());
            }
 
            

11
Class Activity
 Write a program to print Array {22,50,11, 2, 49} in
Reverse Order.
 Write a program to store and print the three different
values (Book Name, Author and Publisher Name) in
different arrays.

12

You might also like