D2 Object Oriented Programming

410 views
330 views

Published on

How to implementation OOP concept with C#

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
410
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

D2 Object Oriented Programming

  1. 1. Object-Oriented Programming Pakorn Weecharungsan
  2. 2. Contents  Introduction to Object-Oriented Programming  Defining Classes  Defining Class Members
  3. 3. Object-Oriented Concept  Class  Instance  Method  Inheritance  Abstraction  Encapsulation  Polymorphism
  4. 4. Programs and Classes
  5. 5. Declaring a class  The class name  Bank  The members of the class  Fields  BankName  Methods  GetAccounts  The characteristics of the class  Public or Private
  6. 6. Declaring a class
  7. 7. Class Members  Fields – A field is variable that belongs to a class It can be any type, either predefined or user- defined Like all variables, fields store data, and have the following characteristics  They can be written to  They can be read from
  8. 8. Class Members  Syntax  Example
  9. 9. Class Members  Methods - A method is a named block of executable code that can be executed fro m many different parts of the program, an d even from other programs Return type Name Parameter list Method body
  10. 10. Class Members
  11. 11. Creating Variables and Instances of a Class
  12. 12. Access Modifiers  private  public  protected  internal  protected internal
  13. 13. Access Modifiers
  14. 14. Access Modifiers  Private Access - Private members are only accessible from within the class in which they are declared-other classes cannot see or access them  Private access is the default access level-so if a member is declared without an access modifier, it is a private member
  15. 15. Access Modifiers  Public Access - Public members are accessible to all other objects in the program. You must use the public ac cess modifier to specify public access
  16. 16. Access Modifiers
  17. 17. Accessing Members from Inside the Class
  18. 18. Accessing Members from Outside the Class
  19. 19. Putting It All Together
  20. 20. Methods  The method header  The method body
  21. 21. Method Invocations
  22. 22. Return Value
  23. 23. The Return Statement and Void Methods
  24. 24. Parameters
  25. 25. Value Parameters
  26. 26. Reference Parameters
  27. 27. Parameter Arrays
  28. 28. Method Overloading  The name of the method  The number of parameters  The data types and order of the parameters
  29. 29. Method Overloading
  30. 30. Properties
  31. 31. Instance Constructors
  32. 32. Destructors
  33. 33. Classes and Inheritance  Class Inheritance  Accessing the Inherited Members  Member Access Modifiers
  34. 34. Class Inheritance
  35. 35. Accessing the Inherited Members
  36. 36. Member Access Modifiers  public  All classes both inside and outside the assembly have free access to the member  private  A private class member can be accessed only by members of its own class. It cannot be accessed by other classes, including classes that are derived from it  A private member can, however, be accessed by members of classes nested in its class
  37. 37. Member Access Modifiers  protected The protected access level is like the private access level, except that it allows classes derived from the class to access the member  internal Members marked internal are visible to all the classes in the assembly, but not to classes outside the assembly
  38. 38. Member Access Modifiers  protected internal Members marked protected internal are visible to all the classes that inherit from the cl ass, and also to all classes inside the assembl y
  39. 39. Summary of Member Access Modifiers
  40. 40. Summary of Member Access Modifiers

×