Your SlideShare is downloading. ×
Chapter 5 declaring classes  & oop
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Chapter 5 declaring classes & oop

448

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
448
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CHAPTER 5 DECLARING CLASSES , ENCAPSULATION , INHERITANCE , POLYMORPHISM , ABSTRACT AND EXCEPTION HANDLING
  • 2. PAG WALA ENCAPSULATION MAWAWALA ANG DANGAL AT INTEGRIDAD NG PROGRAM
  • 3. ENCAPSULATION
    • Encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions). Older languages did not enforce any property/method relationships. This often resulted in side effects where variables had their contents changed or reused in unexpected ways and spaghetti code that was difficult to unravel, understand and maintain. Encapsulation is one of three fundamental principles in object oriented programming .
  • 4. DATA HIDING
    • Data hiding is the ability of objects to shield variables from external access. It is a useful consequence of the encapsulation principle. Those variables marked as private can only be seen or modified through the use of public accessor and mutator methods. This permits validity checking at run time. Access to other variables can be allowed but with tight control on how it is done. Methods can also be completely hidden from external use. Those that are made visible externally can only be called by using the object's front door (ie. there is no 'goto' branching concept).
  • 5. CLASS
  • 6.  
  • 7.  
  • 8. METHODS
  • 9.  
  • 10. CONSTRUCTOR
  • 11.  
  • 12. Constructors are used to initialize instance variables There is always at least one constructor in every class. If a programmer does not define a constructor, the compiler automatically creates one.
  • 13. this
    • EVERY OBJECT CAN ACCESS A REFERENCE TO ITSELF
  • 14.  
  • 15.  
  • 16. Final items cannot be modified. In the case of classes and methods, it means they cannot be extended or overridden, respectively. Native methods are implemented using a language other than Java, usually C or C++. Synchronized methods can be executed by only one thread at a time. Volatile fields are eliminated from certain compiler optimizations regarding references to them. Transient fields are ones that will not be saved when an object is serialized. Static items can be referenced using the name of the class in which they are defined to access them. They are not associated with class instances, although they can be referenced using instance variables. Final items cannot be modified. In the case of classes and methods, it means they cannot be extended or overridden, respectively. MODIFIERS/ QUALIFIERS
  • 17.  
  • 18.  
  • 19.  
  • 20.  
  • 21. TAGA CONTROL NG ACCESS ALSO DEFINE THE BOUNDARY OF AN OBJECT WITH IN THE PACKAGE LANG PUWEDE MAG EXPLORE
  • 22.  
  • 23.  
  • 24.  
  • 25.  
  • 26.  
  • 27.  
  • 28.  
  • 29. COMPOSITION
    • A CLASS CAN HAVE REFERENCES TO OBJECT OF OTHER CLASSES AS MEMBER.
    • set – modify the variable value to ensure the new value is approximate for that data item.
    • get - control how the client can access the variable.
  • 30. Main Class
  • 31. SubClass
  • 32. PRIVATE STRING NAME +setName(name:String):void +setGrade(grade:double):void () – attributes or parameter argument
  • 33. This class declaration. The class body ( the area between the braces) contains all The code that provides for the objects created from the class: constructors for Initializing new objects, declaring for the fields that provide the state of the class and its object, and methods to implement the behavior of the class and its objects.
  • 34.
    • Field declarations are composed of 3 components in order:
    • Zero or more modifiers such as public and private
    • The field’s type.
    • 3. The field’s name.
  • 35.  
  • 36.  
  • 37.  
  • 38.  
  • 39. toString
    • The toString method is widely implemented. It provides a simple, convenient mechanism for debugging classes during development. It is also widely used for logging, and for passing informative error messages to Exception constructors and assertions. When used in these informal ways, the exact format of toString is not part of the contract of the method, and callers should not rely on the exact format of the returned String. The toString method may occasionally be used more formally, however. An example is a simple mechanism for translating an object into a well-defined textual form (toString) and back again (valueOf). In this case, it is particularly important to specify the exact form of such text in javadoc.
    • When implementing toString, StringBuilder can be used instead of the + concatenation operator, since the StringBuilder.append operation is slightly faster.
  • 40.  
  • 41.  
  • 42.  
  • 43.  
  • 44.  
  • 45.  
  • 46.  
  • 47.  
  • 48.  
  • 49.  
  • 50.  
  • 51.  
  • 52. EXAMPLE OF INHERITANCE
  • 53.  
  • 54.  
  • 55.  
  • 56.  
  • 57.  
  • 58.  
  • 59.  
  • 60.  
  • 61.  
  • 62.  
  • 63.  
  • 64.  
  • 65.  
  • 66.  
  • 67.  
  • 68.  
  • 69.  
  • 70.  
  • 71. INHERITANCE
    • indicates the capability of a class to be inherited or extended by other classes. abstract classes must be extended and final classes can never be extended by inheritance. The default (ie. omitted) indicates that the class may or may not be extended at the programmers discretion.
    • Class_name has initial letter capitalized by Java convention.
    • The third option of extends is described in the tutorial on inheritance .
    • The fourth option of implements is described in the tutorial on interfaces .
  • 72.  
  • 73.  
  • 74.  
  • 75.  
  • 76.  
  • 77.  
  • 78.  
  • 79.  
  • 80.  
  • 81.  
  • 82.  
  • 83.  
  • 84.  
  • 85.  
  • 86.  
  • 87.  
  • 88.  
  • 89.  
  • 90.  
  • 91.  
  • 92.  
  • 93.  
  • 94.  
  • 95.  
  • 96.  
  • 97.  
  • 98.  
  • 99.  
  • 100.  
  • 101.  
  • 102.  
  • 103.  
  • 104.  
  • 105.  
  • 106.  
  • 107.  
  • 108.  
  • 109.  
  • 110.  
  • 111.  
  • 112.  
  • 113.  
  • 114.  
  • 115.  
  • 116.  
  • 117. INTRODUCING FINAL VERSION OF STUDENT RECORD APPLICATION BY ENGINEER JESS DALE DELA CRUZ
  • 118.  
  • 119.  
  • 120.  
  • 121.  
  • 122.  
  • 123.  
  • 124.  
  • 125. STUDENT
  • 126.  
  • 127.  
  • 128.  
  • 129.  
  • 130.  
  • 131.  
  • 132.  
  • 133.  
  • 134.  
  • 135.  
  • 136.  
  • 137. TEACHER
  • 138.  
  • 139.  
  • 140.  
  • 141.  
  • 142.  
  • 143.  
  • 144.  
  • 145.  
  • 146.  
  • 147.  
  • 148.  
  • 149.  
  • 150.  
  • 151.  
  • 152.  
  • 153.  
  • 154.  
  • 155.  
  • 156.  
  • 157.  
  • 158.  
  • 159.  
  • 160.  
  • 161.  
  • 162.  

×