Вы находитесь на странице: 1из 17

Emerging Technologies (IT-3302)

Week 04

Usman Akbar
usman.akbar@superior.edu.pk
FB Group - SuperiorUniversity2016
Lecture Review

Last lecture review


 C# - if Statement & if- else if () // Login example
 C# - Nested if Statements // Login with User-Types
 C# - Switch Statement

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 2


Lecture Content

 C # Classes / Objects / Methods


 C# - Encapsulation
 Public
 Private
 Protected

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 3


C# Classes & Object / Data Members & Methods

 When you define a class, you define a blueprint for a data type.
 Object of the class consists of and what operations can be performed on that
object.
 Objects are instances of a class. The methods and variables that constitute a
class are called members of the class.

Class definition starts with the keyword class followed by the


class name; and the class body enclosed by a pair of curly
braces

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 4


Classes in C#

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 5


Data members / Methods

SetName Parameter List

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 6


C# - Encapsulation

 Encapsulation is defined 'as the process of enclosing one or more items within
a physical or logical package’.
 Encapsulation, in object oriented programming methodology, prevents access
to implementation details.
 Abstraction and encapsulation are related features in object oriented
programming. Abstraction allows making relevant information visible and
encapsulation enables a programmer to implement the desired level of
abstraction.

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 7


Access Specifier

Encapsulation is implemented by using access specifiers.


An access specifier defines the scope and visibility of a class
member. C# supports the following access specifiers

 Public
 Private
 Protected

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 8


Public Access Specifier

Public access specifier allows a class to expose its member


variables and member functions to other functions and
objects. Any public member can be accessed from outside the
class.

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 9


Private Access Specifier

Private access specifier allows a class to hide its member variables


and member functions from other functions and objects.

Only functions of the same class can access its private members.
Even an instance of a class cannot access its private members

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 10


C# Example for Access Specifier

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 11


Protected Access Specifier

Protected access specifier allows a child class to access the member


variables and member functions of its base class.

This way it helps in implementing inheritance.

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 12


Class Task # 1

Write Console C# Program having user define data type of


Student
having student attributes and method to print these
attributes

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 13


Class Task # 2

Implement a check of age factor… if student is immature


(under 18)
He/She is not allowed to access the Student Portal

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 14


Class Task # 3

This Program should be run until the student Says “No”

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 15


Question

Questions….?
References

 C# 6 for Programmers
 https://www.tutorialspoint.com/csharp
 https://www.visualstudio.com

Social Community Help ….!


 https://code.msdn.microsoft.com/
 https://www.codeproject.com/
 http://stackoverflow.com/

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 20

Вам также может понравиться